Beginners Question - Visual C# - System.Net Assembly and WebRequest

1.4k views Asked by At

Hopefully this is a simple fix I have the code:

using System.Net;

namespace WebGet
{
    public partial class Web
    {
        public static void Main()
        {
            WebRequest webRequest;
        }
    }
}

And I get an error saying it cannot find WebRequest (missing assembly reference) I added System.Net as a reference. Do I need to do something else?

Thanks in advance

3

There are 3 answers

2
Greg Levenhagen On BEST ANSWER

This works

using System.Net;

namespace WebGet
{
    public partial class Web
    {
        public static void Main()
        {
            WebRequest webRequest;
        }
    }
}

The following shows the references needed.

enter image description here

0
Gregory A Beamer On

You should be fine, as all of the references here should be in the core System dll.

0
James On

You only need to add a reference to the System.dll (which should have happened by default) as the WebRequest class is in there but under the System.Net namespace. Try removing your reference to System.Net but keep the namespace declaration.