1 year ago

#372933

test-img

JINS M.THOMAS

SNMP Trap Listener throws exception nullReferenceException

I am creating an SNMP Trap Listener using SNMP Library in c#. I used the following code to receive traps

try
        {
            lst = new Listener();
            lst.AddBinding(new IPEndPoint(IPAddress.Any, 162));  
            lst.MessageReceived += Listener_MessageReceived;
            lst.StartAsync();
        }
        catch (Exception ex)
        {      
        }   
private static void Listener_MessageReceived(object sender, MessageReceivedEventArgs e)
    {
        // SNMP trap recived Here.
        File.AppendAllText("c:/temp/servicelog.log", "Version :" + e.Message.Version + "\n");
        File.AppendAllText("c:/temp/servicelog.log", "Version :" + e.Message.Scope.Pdu.Variables[4].Data.ToString() + "\n");
       
    }

I run this as a service and then I send trpas using Trap Simulator. The following is the output I got in log file.

  • HandleMessage :Enter. HandleMessage System.Collections.Generic.List`1[Lextm.SharpSnmpLib.Messaging.ISnmpMessage]Version :V2*

When I debug it got following error enter image description here

I also get the following enter image description here

c#

snmp

net-snmp

snmp-trap

0 Answers

Your Answer

Accepted video resources