Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. "no overload for ... matches delegate..."

"no overload for ... matches delegate..."

Scheduled Pinned Locked Moved C#
tutorialquestioncsharpcomtools
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bbranded
    wrote on last edited by
    #1

    Hello, This is my first attempt at writing an event handler. I am writing a simple packet capture utility utilizing a .NET interface to the WinPCap lib. However, I've come across an error and do not know how to solve it.

    private void button1_Click(object sender, EventArgs e)
    {
    /* Retrieve the device list */
    List<PcapDevice> devices = Pcap.GetAllDevices();

            //Extract a device from the list
            PcapDevice device = devices\[2\];
            //Register our handler function to the 'packet arrival' event
            device.OnPacketArrival += new SharpPcap.Pcap.PacketArrivalEvent(device\_PcapOnPacketArrival);
            //Open the device for capturing
            //true -- means promiscuous mode
            //1000 -- means a read wait of 1000ms
            device.Open(true, 1000);
            Console.WriteLine("-- Listenning on {0}, hit 'Enter' to stop...",
            device.Description);
            //Start the capturing process
            device.StartCapture();
            //Wait for 'Enter' from the user.
            Console.ReadLine();
            //Stop the capturing process
            device.StopCapture();
            //Close the pcap device
            device.Close();
    
        }
    
        private static void device\_PcapOnPacketArrival(object sender, SharpPcap.Packets.Packet packet)
        {
            DateTime time = packet.PcapHeader.Date;
            int len = packet.Header.Length;
            Console.WriteLine("{0}:{1}:{2},{3} Len={4}",
            time.Hour, time.Minute, time.Second, time.Millisecond, len);
        }
    

    new SharpPcap.Pcap.PacketArrivalEvent(device_PcapOnPacketArrival) throws an error: "No overload for 'device_PcapOnPacketArrival' matches delegate 'SharpPcap.Pcap.PacketArrivalEvent'" Here is some information that may prove useful: "public delegate void PacketArrivalEvent(object sender, SharpPcap.PcapCaptureEventArgs e) Member of SharpPcap.Pcap" Also, I am referring to the outdate sample code located on the main site for the class wrapper. How can I avoid this error? Any assistance is appreciated. Thanks, Matt

    G L 2 Replies Last reply
    0
    • B bbranded

      Hello, This is my first attempt at writing an event handler. I am writing a simple packet capture utility utilizing a .NET interface to the WinPCap lib. However, I've come across an error and do not know how to solve it.

      private void button1_Click(object sender, EventArgs e)
      {
      /* Retrieve the device list */
      List<PcapDevice> devices = Pcap.GetAllDevices();

              //Extract a device from the list
              PcapDevice device = devices\[2\];
              //Register our handler function to the 'packet arrival' event
              device.OnPacketArrival += new SharpPcap.Pcap.PacketArrivalEvent(device\_PcapOnPacketArrival);
              //Open the device for capturing
              //true -- means promiscuous mode
              //1000 -- means a read wait of 1000ms
              device.Open(true, 1000);
              Console.WriteLine("-- Listenning on {0}, hit 'Enter' to stop...",
              device.Description);
              //Start the capturing process
              device.StartCapture();
              //Wait for 'Enter' from the user.
              Console.ReadLine();
              //Stop the capturing process
              device.StopCapture();
              //Close the pcap device
              device.Close();
      
          }
      
          private static void device\_PcapOnPacketArrival(object sender, SharpPcap.Packets.Packet packet)
          {
              DateTime time = packet.PcapHeader.Date;
              int len = packet.Header.Length;
              Console.WriteLine("{0}:{1}:{2},{3} Len={4}",
              time.Hour, time.Minute, time.Second, time.Millisecond, len);
          }
      

      new SharpPcap.Pcap.PacketArrivalEvent(device_PcapOnPacketArrival) throws an error: "No overload for 'device_PcapOnPacketArrival' matches delegate 'SharpPcap.Pcap.PacketArrivalEvent'" Here is some information that may prove useful: "public delegate void PacketArrivalEvent(object sender, SharpPcap.PcapCaptureEventArgs e) Member of SharpPcap.Pcap" Also, I am referring to the outdate sample code located on the main site for the class wrapper. How can I avoid this error? Any assistance is appreciated. Thanks, Matt

      G Offline
      G Offline
      Gideon Engelberth
      wrote on last edited by
      #2

      Look closely at how the two are declared:

      void device_PcapOnPacketArrival(object sender, SharpPcap.Packets.Packet packet)
      delegate void PacketArrivalEvent(object sender, SharpPcap.PcapCaptureEventArgs e)

      See the difference?

      B 1 Reply Last reply
      0
      • B bbranded

        Hello, This is my first attempt at writing an event handler. I am writing a simple packet capture utility utilizing a .NET interface to the WinPCap lib. However, I've come across an error and do not know how to solve it.

        private void button1_Click(object sender, EventArgs e)
        {
        /* Retrieve the device list */
        List<PcapDevice> devices = Pcap.GetAllDevices();

                //Extract a device from the list
                PcapDevice device = devices\[2\];
                //Register our handler function to the 'packet arrival' event
                device.OnPacketArrival += new SharpPcap.Pcap.PacketArrivalEvent(device\_PcapOnPacketArrival);
                //Open the device for capturing
                //true -- means promiscuous mode
                //1000 -- means a read wait of 1000ms
                device.Open(true, 1000);
                Console.WriteLine("-- Listenning on {0}, hit 'Enter' to stop...",
                device.Description);
                //Start the capturing process
                device.StartCapture();
                //Wait for 'Enter' from the user.
                Console.ReadLine();
                //Stop the capturing process
                device.StopCapture();
                //Close the pcap device
                device.Close();
        
            }
        
            private static void device\_PcapOnPacketArrival(object sender, SharpPcap.Packets.Packet packet)
            {
                DateTime time = packet.PcapHeader.Date;
                int len = packet.Header.Length;
                Console.WriteLine("{0}:{1}:{2},{3} Len={4}",
                time.Hour, time.Minute, time.Second, time.Millisecond, len);
            }
        

        new SharpPcap.Pcap.PacketArrivalEvent(device_PcapOnPacketArrival) throws an error: "No overload for 'device_PcapOnPacketArrival' matches delegate 'SharpPcap.Pcap.PacketArrivalEvent'" Here is some information that may prove useful: "public delegate void PacketArrivalEvent(object sender, SharpPcap.PcapCaptureEventArgs e) Member of SharpPcap.Pcap" Also, I am referring to the outdate sample code located on the main site for the class wrapper. How can I avoid this error? Any assistance is appreciated. Thanks, Matt

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Gideon is right. Your method signature does not match the delegate signature. If you are using Visual Studio, it automatically creates the method stub with the correct signature for you.

        1 Reply Last reply
        0
        • G Gideon Engelberth

          Look closely at how the two are declared:

          void device_PcapOnPacketArrival(object sender, SharpPcap.Packets.Packet packet)
          delegate void PacketArrivalEvent(object sender, SharpPcap.PcapCaptureEventArgs e)

          See the difference?

          B Offline
          B Offline
          bbranded
          wrote on last edited by
          #4

          Thanks soo much guys. I sincerely appreciate the explanation. Event handlers? Check.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups