2017-06-28 25 views
1
我在Fedora 25我以前 these instructions用的RPM我分發安裝DOTNET,因爲有在Fedora 25沒有正式使用的軟件包DOTNET

存在一切正常:DOTNET中的Fedora 25:</p> <p>:Web客戶端不System.Net

$ dotnet --version 
1.0.0-preview2-1-003175 

我想運行一個簡單的WebClient的例子,用Visual代碼創建:

using System; 
using System.Net; 
using System.Net.Http; 
using System.Net.WebClient; 

namespace ConsoleApplication 
{ 
    public class Program 
    { 
     public static void Main(string[] args) 
     { 
      using (var webClient = new WebClient()) 
      { 
       var url = [someurl]; 
       var htmlCode = webClient.DownloadData(url); 
       var base64 = Convert.ToBase64String(htmlCode); 
      } 
     } 
    } 
} 

請注意,我說的using只陳述一個接一個,運行到這個問題:

$ dotnet build 
Project cbsearchui_test (.NETCoreApp,Version=v1.1) will be compiled because expected outputs are missing 
Compiling test_project for .NETCoreApp,Version=v1.1 
/usr/lib64/dotnetcore/dotnet compile-csc 
@test_project/obj/Debug/netcoreapp1.1/dotnet- 
compile.rsp returned Exit Code 1 
test_project/Program.cs(4,18): error CS0234: 
The type or namespace name 'WebClient' does not exist in the namespace 
'System.Net' (are you missing an assembly reference?) 

Compilation failed. 
    0 Warning(s) 
    1 Error(s) 

Time elapsed 00:00:00.6661503 

這是我project.json,由VS自動生成代碼:

{ 
    "version": "1.0.0-*", 
    "buildOptions": { 
    "debugType": "portable", 
    "emitEntryPoint": true 
    }, 
    "dependencies": {}, 
    "frameworks": { 
    "netcoreapp1.1": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.1.0" 
     } 
     }, 
     "imports": "dnxcore50" 
    } 
    } 
} 

我努力理解,如果這是有關我的具體Dotnet安裝和/或Fedora 25.類似的問題似乎是指compatibility issues,profiling,bad usage statement等,但它們都不適用於這個問題。

我也嘗試將依賴項更改爲netcoreapp版本1.0.0而不是1.1.0,但仍然存在相同的錯誤。

+0

據我所知,在2.0版本之前,WebClient不存在於dotnet核心中。 –

+0

https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient?view=netcore-2.0 –

+0

只是不要使用WebClient,它已經過時了。它已被替換爲HttpClient,即使在Windows上的.NET Framework項目中也是如此 –

回答

0

作爲評論的結論,答案是:WebClient不能用於(Fedora)Linux,因爲.NET 2.0不可用。 解決方法是使用HttpClient代替。

相關問題