[英]Dotnet in Fedora 25: WebClient does not exist in System.Net
I am using Dotnet on Fedora 25. I used these instructions to install Dotnet with RPMs for my distribution, as there are no official packages for Fedora 25: 我在Fedora 25上使用Dotnet。我使用这些说明为我的发行版安装了Dotnet和RPMs,因为Fedora 25没有官方软件包:
Things look fine: 事情看起来很好:
$ dotnet --version
1.0.0-preview2-1-003175
I am trying to run a simple WebClient example, created with Visual Code: 我试图运行一个简单的WebClient示例,使用Visual Code创建:
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);
}
}
}
}
Note that I added the using
statements one-by-one, running into this issue: 请注意,我逐个添加了
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
This is my project.json
, automatically generated by VS Code: 这是我的
project.json
,由VS Code自动生成:
{
"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"
}
}
}
I am struggling to understand if this is related to my specific Dotnet installation and/or to Fedora 25. Similar questions seem to refer to compatibility issues , profiling , bad usage statement etc. But none of them seem applicable to this issue. 我很难理解这是否与我的特定Dotnet安装和/或Fedora 25相关。类似的问题似乎是指兼容性问题 , 分析 , 错误的使用声明等。但它们似乎都不适用于这个问题。
I also tried changing the dependency to netcoreapp
to version 1.0.0 instead of 1.1.0, but the same error persists. 我也尝试将依赖关系更改为
netcoreapp
到版本1.0.0而不是1.1.0,但同样的错误仍然存在。
As a conclusion from the comments, the answer is: WebClient
cannot be used in (Fedora) Linux because .NET 2.0 is not available. 作为评论的结论,答案是:
WebClient
不能用于(Fedora)Linux,因为.NET 2.0不可用。 Solution is to use HttpClient
instead. 解决方案是使用
HttpClient
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.