使用System.Net;找不到IPEndPoint

时间:2012-02-17 23:16:34

标签: c# mono monodevelop

我过去对monodevelop和csharp litle经验不熟悉。

尝试做这个例子: http://sharpsnmplib.codeplex.com/wikipage?title=600009&referringTitle=KB

我得到并且错误

  

TestAsyncGet / Program.cs(32,32):错误CS0246:找不到类型或命名空间名称“IPEndPoint”。您是否缺少using指令或程序集引用? (CS0246)(TestAsyncGet)

感谢您的帮助。

在参考文献中,System.Net也抱怨:

  

Projects / TestAsyncGet / TestAsyncGet / Program.cs(13,13):错误CS0825:上下文关键字“var”可能只出现在局部变量声明中(CS0825)(TestAsyncGet)

从命令行运行:

  

mono TestAsyncGet.exe System.FormatException:输入字符串不在   System.Int64.Parse(System.String s)[0x00000]的正确格式   in:在TestAsyncGet.Program.Main为0   (System.String [] args)[0x00000] in:0

GetRequestMessage message = new GetRequestMessage(0,
                VersionCode.V1,
                new OctetString("stvtelco"),
                new List<Variable> {new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.4"))});
    long ip = Int64.Parse("192.168.0.33");
            var endpoint = new IPEndPoint(new IPAddress(ip), 161);

            message.BeginGetResponse(endpoint, new UserRegistry(), endpoint.GetSocket(), ar => {
                var response = message.EndGetResponse(ar);
                Console.WriteLine(response);
            }, null);
            Console.Read();

1 个答案:

答案 0 :(得分:1)

确保你是:

  • 使用.NET 4.0配置文件构建。这将选择dmcs编译器并启用var关键字语法;

  • 在项目中引用System.dll程序集。这是System.Net命名空间驻留在常规框架上的地方(对于Silverlight来说有点不同,因为它有System.Net.dll程序集);

  • 文件顶部有using System.Net;

根据这些条件,您应该能够正确编译此代码。