1

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.

Carsten
  • 1,406
  • 19
  • 44
  • As far as I'm aware, WebClient doesn't exist in dotnet core until version 2.0. – J. Steen Jun 28 '17 at 09:58
  • https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient?view=netcore-2.0 – J. Steen Jun 28 '17 at 10:03
  • Just don't use WebClient, it's obsolete. It's been replaced by HttpClient even in .NET Framework projects on Windows – Panagiotis Kanavos Jun 29 '17 at 10:15
  • This comment seems to conflict with the earlier ones. @J.Steen's comment indicates that I need a more recent .NET core version to use `WebClient` wheras @panagiotis says that `WebClient` is obsolete. Should the solution hence be to upgrade .NET core (once it is available for (Fedora) Linux) or to replace `WebClient` with `HttpClient`? – Carsten Jun 30 '17 at 12:59
  • You could simply use HttpClient instead. It's more "advanced", but is already implemented and will likely not go away anytime soon. – J. Steen Jun 30 '17 at 13:07

1 Answers1

0

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.

Carsten
  • 1,406
  • 19
  • 44