1

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

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Greycrow
  • 1,603
  • 5
  • 19
  • 29
  • Nope, that's not an easy one. Unless you target the Micro framework. – Hans Passant Jan 31 '11 at 23:53
  • Since you've said you are a beginner, let me add a tip: Always check the [MSDN documentation](http://msdn.microsoft.com/en-us/library/system.net.webrequest%28v=VS.100%29.aspx) for any framework class you're having trouble referencing; you'll notice it shows you not only which namespace it's in, but which DLL (the confusing bit in this case being that the System.Net namespace does not reside entirely in the eponymous DLL!) :) – Dan J Feb 01 '11 at 01:30

3 Answers3

1

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

Greg Levenhagen
  • 924
  • 7
  • 14
  • Thanks :) I added System.Net but Not System ... That worked Thanks! – Greycrow Feb 01 '11 at 00:03
  • Pretty much every program you'll ever write requires System.dll. If you're using .NET 3.5 or higher, you'll also nearly always need System.Core.dll (assuming you're using any of the 3.5+ stuff like LINQ). You're probably safe removing the references to things like System.Data and some of the other defaults, but I'd always recommend leaving System and System.Core in every project, every time. – Joe Enos Feb 01 '11 at 00:18
0

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

Gregory A Beamer
  • 16,870
  • 3
  • 25
  • 32
0

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.

James
  • 80,725
  • 18
  • 167
  • 237