简体   繁体   中英

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

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

This works

using System.Net;

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

The following shows the references needed.

在此处输入图片说明

您应该还可以,因为此处的所有参考都应位于核心System dll中。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM