不是csc /r:System.Net.all 是csc /r:System.Net.dll

解决方案 »

  1.   

    hehe粗心啊,我就经常范这样的错误,而且一次性几十个 :)
      

  2.   

    我运行没错啊,除了你的IPAddress属性被我删掉,改直接用m_arrIPs,把它设为public
      

  3.   

    加入名字空间using System.Net.Sockets;
    就可以了,我在局域网中测试通过!
      

  4.   

    错了,错了。错了。sorry!
      

  5.   

    using System;
    using System.Net;
    class ResolveDNS
    {
    public int m_arrIPs;
        public IPAddress[] ips;
    public void Resolve(string strHost)
    {
    IPHostEntry iphe=Dns.GetHostByName(strHost);
    m_arrIPs=iphe.AddressList.Length;
    ips=iphe.AddressList;
    }
        public int Count
    {
    get { return m_arrIPs; }
    }
    }class DNSResolverApp
    {
    public static void Main()
    {
    ResolveDNS myDNSResolver=new ResolveDNS();
    myDNSResolver.Resolve("http://www.chinaren.com"); int nCount=myDNSResolver.Count;
    Console.WriteLine("Found {0} IP's for hostname",nCount);
    for(int i=0; i<nCount; i++)

    Console.WriteLine(myDNSResolver.ips[i]);
    Console.ReadLine();
    }
    }
    }
    编译通过
      

  6.   

    编译的时候/r:system.dll,不是system.net.dll
    把http://www.chinaren.com改成www.chinaren.com,去掉http://就行了。
    为什么不仔细读读exception的内容呢?参见:http://www.csdn.net/Expert/topic/498/498580.shtm
    回复人: CForce() (2002-1-25 13:08:47)  得0分 
    c:>csc /r:System.Net.dll /out:1.exe Test.cs  改为:
    c:>csc /r:System.dll /out:1.exe Test.cs   回复人: qqchen79(知秋一叶) (2002-1-26 0:23:10)  得0分 
      CForce说得没错,你还是要区别Namespace和Reference的区别!
      System.Net是一个Namespace而已,它可以实现在任何一个Assembly当中,实际上,System.NET中的IPHostEntry等类仍然是实现在System.DLL当中的。所以你需要加的是System.dll的引用。
    如果你查MSDN的文档,那么在类的overview页底下会有这么一段:
    Requirements
    Namespace: System.Net  <---- 这个是Namespace,就是using语句用的。
    Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family
    Assembly: System (in System.dll) <---- 这个是Assembly,是csc /r:用的。
     
    如果编译通过,证明你的引用是没问题的,因为.NET库引用不用与.lib文件,不是“连接”到你的exe里的,而只是添加了一个引用。
    你的程序出现exception是因为HostName参数有问题:http://是协议部分,不属于HostName, 真正的HostName应该是"www.windows.com",如此而已。  
      

  7.   

    唉!上个贴子都没给分呢!//sigh, 江河日下。
      

  8.   

    qqchen79(知秋一叶)的方法完全正确我已编译, 运行通过!!!
      

  9.   

    Sorry,不是说你, 我的意思是C#版的结贴率太低了。:)
    我回答同样问题的上一个贴子到现在还没结呢!