2
  • I installed dotnet via sudo apt-get install dotnet
  • I created a project using dotnet new hello-world template. It builds and runs.
  • Architecture: amd64 (dpkg -s)
  • Version: 1.0.0.001598-1 (dpkg -s)

Then I wanted to start using the library System.Net so I altered the template. I added a using directive and a code snippet directly from the Microsoft API docs.

I get errors, specifically that the classes are not found in the System.Net namespace. Note the compiler doesn't complain that my using is bad (i.e. doesn't recognize the namespace), it just can't find the types in that namespace.

The reason that surprises me is because in the api docs these classes are specified as part of .Net core, so I assumed they would be available "out-of-the-box".

dotnet restore; dotnet update yields:

sr/share/dotnet/bin/dotnet compile-csc @/home/scratch/newapp/obj/Debug/dnxcore50/dotnet-compile.rsp returned Exit Code 1
/home/scratch/newapp/Program.cs(10,13): error CS0246: The type or namespace name 'HttpWebRequest' could not be found (are you missing a using directive or an assembly reference?)
ome/scratch/newapp/Program.cs(11,33): error CS0103: The name 'WebRequest' does not exist in the current context
ome/newapp/Program.cs(11,18): error CS0246: The type or namespace name 'HttpWebRequest' could not be found (are you missing a using directive or an assembly reference?)

(sic: the truncated shell output is AS-IS)

Here is my code.

using System;
using System.Net;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            HttpWebRequest myReq =
                (HttpWebRequest)WebRequest.Create("http://www.contoso.com/");
            Console.WriteLine("Hello World!");
        }
    }
}

What am I missing? Isn't System.Net in the standard libs that come with .Net Core? I browsed CoreFX, but I got the feeling it is just a component of .Net Core and I should have it. If not, how do I install that?

Wilbur Whateley
  • 201
  • 1
  • 11

1 Answers1

1

Use http://packagesearch.azurewebsites.net to search for the missing packages. Then you can modify your project.json to add a reference to the found packages, such as System.Net.Primitives, System.Net.Sockets and so on.

However, in your case, WebRequest is not yet available in any RC1 package. You will have to wait till Microsoft ports it, or simply switch to other classes, such as HttpClient.

The API reference site is not accurate right now, as I believe it was built against some build between RC1 and RC2. Many types appear in the API reference, but they would only be available when Microsoft publishes RC2.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • Ok I'm totally confused now, what does Azure have to do with any of this? The api reference in the .NET core docs specify this namespace, and the compiler recognizes the names space, but I still have to call out namespace dependencies explicitly in the project? These aren't in the core? – Wilbur Whateley Mar 08 '16 at 18:39
  • Oh, I see, the package lookup is just hosted there at azurewebsites.net. – Wilbur Whateley Mar 08 '16 at 20:26
  • Ok I went there, but I want to use classes directly in the `System.net` namespace, not `.primitives` or `.utilities` or anything. What package do I need? The [API reference](http://dotnet.github.io/api/index.html) on dotnet.github.io suggests that, for example, `System.Net.WebRequest` exists. What do I need from the package search? – Wilbur Whateley Mar 08 '16 at 20:29
  • Given all this I'm really biting my tongue here (if you can't say something nice...about Microsoft...), but one thing I'm really wondering is you said "Microsoft ports it". Isn't it the "foundation/community" that should be porting it? – Wilbur Whateley Mar 09 '16 at 19:02
  • @WilburWhateley Generally speaking, it is mainly Microsoft who drives the project at this stage, where it publishes the source code from .NET Framework and lies a solid ground for the community to step in. The BSD port is fully contributed by the community. The community will do more upon 1.0 I think, but not quite much right now. – Lex Li Mar 10 '16 at 00:59