Hello. I've downloaded decompiled version of one dll writen on C#. And when i try to use the code in C# there is the following errors: "Error 1 The type 'dotnetWinpCap' already contains a definition for 'OnReceivePacket' C:\Documents and Settings\Owner\My Documents\Projects\MBwpcap\MBwpcap\Class1.cs 233 46 MBwpcap
", "Error 2 Inconsistent accessibility: field type 'dotnetWinpCap.ReceivePacket' is less accessible than field 'dotnetWinpCap.OnReceivePacket' C:\Documents and Settings\Owner\My Documents\Projects\MBwpcap\MBwpcap\Class1.cs 233 46 MBwpcap
", "Error 3 The type 'dotnetWinpCap' already contains a definition for 'OnDumpEnded' C:\Documents and Settings\Owner\My Documents\Projects\MBwpcap\MBwpcap\Class1.cs 234 43 MBwpcap
" and "Error 4 The type 'dotnetWinpCap' already contains a definition for 'OnReceivePacketInternal' C:\Documents and Settings\Owner\My Documents\Projects\MBwpcap\MBwpcap\Class1.cs 235 55 MBwpcap
"
This is a part of the code:
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
public class Device
{
private string name;
private string description;
private string address;
private string netmask;
public Device()
{
name = null;
description = null;
address = null;
netmask = null;
return;
}
public virtual string Name
{
get
{
return name;
}
set
{
name = value;
return;
}
}
public virtual string Description
{
get
{
return description;
}
set
{
description = value;
return;
}
}
public virtual string Address
{
get
{
return address;
}
set
{
address = value;
return;
}
}
public virtual string Netmask
{
get
{
return netmask;
}
set
{
netmask = value;
return;
}
}
}
public class dotnetWinpCap
{
public class AlreadyOpenException : Exception
{
public AlreadyOpenException()
{
return;
}
public override string Message
{
get
{
return "Device attached to object already open. Close first before reopening";
}
}
}
delegate void packet_handler(int param, int header, int pkt_data);
public enum PCAP_NEXT_EX_STATE
{
SUCCESS = 1,
TIMEOUT = 0,
ERROR = -1,
EOF = -2,
UNKNOWN = -3,
}
delegate void ReceivePacket(object sender, PacketHeader p, System.Byte[] s);
delegate void DumpEnded(object sender);
delegate void ReceivePacketInternal(object sender, int header, int data);
public struct pcap_pkthdr
{
public dotnetWinpCap.timeval ts;
public UInt32 caplen;
public UInt32 len;
}
public struct timeval
{
public UInt32 tv_sec;
public UInt32 tv_usec;
}
private struct pcap_rmtauth
{
private int type;
private string username;
private string password;
}
private struct in_addr
{
public char b1;
public char b2;
public char b3;
public char b4;
public UInt16 w1;
public UInt16 w2;
public UInt64 addr;
}
private struct sockaddr
{
public short family;
public UInt16 port;
public System.Byte[] addr;
public System.Byte[] zero;
}
private struct pcap_addr
{
public int next;
public int addr;
public int netmask;
public int broadaddr;
public int dstaddr;
}
private struct pcap_if
{
public int next;
public string name;
public string description;
public int addresses;
public UInt32 flags;
}
private Thread ListenThread;
private bool disposed;
private dotnetWinpCap.packet_handler callback;
private string fname;
private int maxb;
private int maxp;
private bool m_islistening;
private bool m_isopen;
private string m_attachedDevice;
private int pcap_t;
private int dumper;
private dotnetWinpCap.ReceivePacket OnReceivePacket;
private dotnetWinpCap.DumpEnded OnDumpEnded;
private dotnetWinpCap.ReceivePacketInternal OnReceivePacketInternal;
private StringBuilder errbuf;
public dotnetWinpCap()
{
ListenThread = null;
disposed = 0;
callback = null;
fname = "";
maxb = 0;
maxp = 0;
m_islistening = 0;
m_isopen = 0;
m_attachedDevice = null;
pcap_t = IntPtr.Zero;
dumper = IntPtr.Zero;
errbuf = new StringBuilder(256);
return;
}
public virtual string AttachedDevice
{
get
{
return m_attachedDevice;
}
}
public virtual string LastError
{
get
{
return errbuf.ToString();
}
}
public virtual bool IsListening
{
get
{
return m_islistening;
}
}
public virtual bool IsOpen
{
get
{
return m_isopen;
}
}
public event dotnetWinpCap.ReceivePacket OnReceivePacket;
private event dotnetWinpCap.DumpEnded OnDumpEnded;
private event dotnetWinpCap.ReceivePacketInternal OnReceivePacketInternal;
How can i resolve that problem
Excuse me for that long post... Thanks!

Decompiled DLL
Kentmw
Destructors are the C# mechanism for performing cleanup operations. Destructors provide appropriate safeguards, such as automatically calling the base type's destructor. In C# code, Object.Finalize cannot be called or overridden.
To correct your error simply change the signiture of your Finalize method from protected override void Finalize() to ~dotnetWinpCap().
That should take care of your error.
JPB
master20
I am not sure why decompile gave you the results it did, but it appears that it has defined your events twice. The first set are marked private and are defined as follows:
private dotnetWinpCap.ReceivePacket OnReceivePacket;
private dotnetWinpCap.DumpEnded OnDumpEnded;
private dotnetWinpCap.ReceivePacketInternal OnReceivePacketInternal;
The last 3 lines of your code redefine the events as :
public event dotnetWinpCap.ReceivePacket OnReceivePacket;
private event dotnetWinpCap.DumpEnded OnDumpEnded;
private event dotnetWinpCap.ReceivePacketInternal OnReceivePacketInternal;
Removing the private versions should resolve your errors.
Of course ... based on these errors I would not be too certain that the decompiled code works as you expect.
Woodyuk
I've removed this lines and the errors were solved! But after that there is one more warning and one error: "Warning 1 Introducing a 'Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor C:\Documents and Settings\Owner\My Documents\Projects\MBwpcap\MBwpcap\Class1.cs 828 29 MBwpcap
" and "Error 2 Do not override object.Finalize. Instead, provide a destructor. C:\Documents and Settings\Owner\My Documents\Projects\MBwpcap\MBwpcap\Class1.cs 828 29 MBwpcap
"
There is a prat of the code:
public class dotnetWinpCap
{
.................
.................
protected override void Finalize()
{
try
{
Dispose(0);
goto ILO_0010;
}
finally
{
base.Finalize();
}
ILO_0010:
return;
}
}
Thanks again :)