使用System.Net;未找到 IPEndPoint
我对 monodevelop 和 csharp 很陌生,过去经验很少。
尝试做#SNMP 库示例。
我得到并错误
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] 处的正确格式 在 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();
I'm new to monodevelop and csharp litle experience in the past.
Trying to do #SNMP Library example.
I get and error
TestAsyncGet/Program.cs(32,32): Error CS0246: The type or namespace name `IPEndPoint' could not be found. Are you missing a using directive or an assembly reference? (CS0246) (TestAsyncGet)
Thank you for any help.
Have in references System.Net also is complaining about:
Projects/TestAsyncGet/TestAsyncGet/Program.cs(13,13): Error CS0825: The contextual keyword `var' may only appear within a local variable declaration (CS0825) (TestAsyncGet)
Running from the command line:
mono TestAsyncGet.exe System.FormatException: Input string was not in
the correct format at System.Int64.Parse (System.String s) [0x00000]
in :0 at TestAsyncGet.Program.Main
(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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您:
使用 .NET 4.0 配置文件进行构建。这将选择 dmcs 编译器并启用 var 关键字语法;
引用项目中的
System.dll
程序集。这是System.Net
命名空间驻留在常规框架上的位置(对于 Silverlight 来说有点不同,因为它有一个System.Net.dll
程序集);在文件顶部有一个
using System.Net;
。有了这些条件,您应该能够正确编译此代码。
Make sure you are:
building with the .NET 4.0 profile. That will select the
dmcs
compiler and will enable thevar
keyword syntax;have a reference to
System.dll
assembly in your project. This is whereSystem.Net
namespace resides on the regular framework (that's a bit different for Silverlight since it has aSystem.Net.dll
assembly);have a
using System.Net;
at the top of your file.With those conditions you should be able to compile this code correctly.