System.BadImageFormatException PcapDotNetCore.dll

Oct 9, 2012 at 10:35 AM
Edited Oct 9, 2012 at 10:47 AM

trying to run my dll using outer programm which is 32-bit application

my dll refereces to PCapDotNet dlls

target platform is x86 and pcap dlls too

the problem is when i try to run function that uses pcap dll funcs i get BadImageFormatException

 

 

void somehandler(obj,eventargs){

...

PCapLoad();    ///<--this is where i get an exception
...

}

 

        void PCapLoad()
        {
            device = new OfflinePacketDevice(LoadFileName);
            try
            {
                communicator = device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000);
            }
            catch (InvalidOperationException e)
            {
                MessageBox.Show(e.Message);
                return;
            }

            PacketCommunicatorReceiveResult res = PacketCommunicatorReceiveResult.Ok;
            do
            {
                int tmp;
                res = communicator.ReceiveSomePackets(out tmp, 0, PacketHandler);
            }
            while (res != PacketCommunicatorReceiveResult.Eof);
        }
i'm using .net framework 4, how can i avoid this situation?
Coordinator
Oct 12, 2012 at 7:11 AM

Please make sure you followed all the steps mentioned in "Using Pcap.Net in your programs" in the Pcap.Net User Guide.

Oct 15, 2012 at 4:51 AM
Edited Oct 15, 2012 at 5:14 AM

i did, thought the first thing i'm missing was MS Visual C++ 2010 Redistributable package.

i 've installed it, but that made no effect

one more thing that i didn't mention about: it's ok when i'm running my project as application

outer programm(win32 application) uses MFC, maybe this causes problems?

Coordinator
Oct 20, 2012 at 2:07 PM

The outer program should be a .NET application.

I'm not sure if it would work otherwise.

Other than that, try and install the Visual C++ 2010 Redistributable packages (x86 AND x64) and the Visual C++ 2008 Redistributable packages (x86 AND x64) and let me know if any of them helps.

 

Boaz.

Oct 25, 2012 at 7:44 AM

tried vc 2005 redistributable package and vc 2008 redistributable package, didn't help either

actually i'm using vs2012express and my mate is using vs2010 professional, i don't think that vcredist package could be the reason

i made shure that i'm building all included libraries for x86 target and that i'm  using correct PCap assembly(for x86)

eventually i tried to run my programm as application on 32bit winxp and i got System.IO.FileFormatException at the same place

Coordinator
Oct 26, 2012 at 7:07 AM

Does it work for your mate?

Oct 29, 2012 at 4:09 AM

no, it doesn't

Coordinator
Nov 23, 2012 at 6:42 PM

Make sure that:

1. If you're using Windows x64, you should use WinPcap x64 and Pcap.Net x64.

2. If you're using Windows x32, you should use WinPcap x32 and Pcap.Net x32.

Dec 7, 2012 at 4:00 AM
brickner wrote:

Make sure that:

1. If you're using Windows x64, you should use WinPcap x64 and Pcap.Net x64.

2. If you're using Windows x32, you should use WinPcap x32 and Pcap.Net x32.

do you want to say that i must use Windows x32 to compile 32bit application?

Dec 7, 2012 at 4:54 AM

Change your target framework from 4.5 to 4.0

Coordinator
Dec 7, 2012 at 1:06 PM
vndtta wrote:
brickner wrote:

Make sure that:

1. If you're using Windows x64, you should use WinPcap x64 and Pcap.Net x64.

2. If you're using Windows x32, you should use WinPcap x32 and Pcap.Net x32.

do you want to say that i must use Windows x32 to compile 32bit application?

You said you had trouble running the program right?

Do you have this exception when you run the program or when you compile it?

Dec 24, 2012 at 5:37 AM
Edited Dec 24, 2012 at 5:39 AM

no, compilation is ok, some warnings related to possible loss of data due to type casting, nothing special

Coordinator
Dec 28, 2012 at 2:41 PM

Pcap.Net 64 bit works with WinPcap 64 bit which works with Windows 64 bit.

Pcap.Net 32 bit works with WinPcap 32 bit which works with Windows 32 bit.

 

Makes sense?

Jan 14, 2013 at 6:58 AM

i've got win64bit, and i want to run my app on win32bit what should i do? judjung on what you saying i should compile 32bit app only on win 32bit

and since i've got win 64bit - 64bit app should be ok on win 64bit, but that's not true

Coordinator
Jan 15, 2013 at 8:13 PM

No, you can compile using Pcap.Net 32 bits dlls.

However, you won't be able to run that application on the 64 bits windows.