Search code examples
c#.netvisual-studio-codefedora-25

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:

Things look fine:

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

I am trying to run a simple WebClient example, created with 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:

$ 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:

{
  "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.

I also tried changing the dependency to netcoreapp to version 1.0.0 instead of 1.1.0, but the same error persists.


Solution

  • As a conclusion from the comments, the answer is: WebClient cannot be used in (Fedora) Linux because .NET 2.0 is not available. Solution is to use HttpClient instead.