Reputation: 201
sudo apt-get install dotnet
dotnet new
hello-world template. It builds and runs.dpkg -s
)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?
Upvotes: 2
Views: 429
Reputation: 63203
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.
Upvotes: 1