1

Executing code that references c:\windows\system32\hnetcfg.dll to manage the Windows Firewall from this question, causes a BadImageFormatException as soon as the DLL is loaded.

Opening the 414KB DLL file in NUnit for inspection throws the same exception.

I am running Windows 7. Any solutions?

Community
  • 1
  • 1
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287

2 Answers2

4

Solved:

...by setting target platform to x86.

Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
4

Is it a 64-bit application trying to reference a 32-bit dll? If so, either get the 64-bit version of the dll or force the application to run in 32-bit using

corflags /32bit+ myApp.exe

Or as you say, just build in 32-bit (x86)

cristobalito
  • 4,192
  • 1
  • 29
  • 41
  • The service using the DLL is now targeted for x86. How can I make sure it will run on 32-bit and 64-bit machines? Do I need two different versions of my application, or can I just target x86? I am running 64-bit Windows and it seems to be working, but I'll need to test it properly. – Petrus Theron Nov 26 '10 at 23:58
  • If (at least) one of your dependencies is 32 bit, then you'll need to force the application (service) to run in 32-bit mode. Targetting for x86 will mean it'll run in 32-bit mode on both x86 and x64 which may be all you need. If you'd like it to run 64-bit on x64, then you'll need to source a 64-bit version of the dll and essentially have two separate executables - one for x86 (build against x86 dll) and one for x64 (build against x64 dll). – cristobalito Nov 27 '10 at 13:09