简体   繁体   中英

using System.Net; IPEndPoint not found

I'm new to monodevelop and csharp litle experience in the past.

Trying to do this example: http://sharpsnmplib.codeplex.com/wikipage?title=600009&referringTitle=KB

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();

Make sure you are:

  • building with the .NET 4.0 profile. That will select the dmcs compiler and will enable the var keyword syntax;

  • have a reference to System.dll assembly in your project. This is where System.Net namespace resides on the regular framework (that's a bit different for Silverlight since it has a System.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.

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