48

I'm using Visual C# Studio 10.0 with .NET Framework 4.0 and I was trying to load in the SoundTouchSharp library and create an instance of the library (object) in my application. However, after I type in the path for the file, I get this error:

BadImageFormatException was unhandled -- An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

How should I fix that? I'm almost positive that I created the .dll using the VS terminal and it should be the same version as the .NET framework. I can also provide more code if needed.

Thanks!

Carsten
  • 11,287
  • 7
  • 39
  • 62
m00nbeam360
  • 1,357
  • 2
  • 21
  • 36
  • http://stackoverflow.com/questions/11370344/could-not-load-file-or-assembly-an-attempt-was-made-to-load-a-program-with-a – Gopesh Sharma Apr 10 '13 at 04:59
  • Please also note that the version of "WebView2Loader.dll" which is in use is very crucial. I had almost the same problem with "Microsoft.WebView2.FixedVersionRuntime.101.0.1210.39.x64" when I tried to use the WebView2 component in the MMC Snap-Ins with types of "HTMLView" or "FormView". – amirfg May 18 '22 at 07:56
  • I just copied the abovementioned dll file (version 1.0.1248.0, size=157640 bytes) in a proper path that was accessible for the project (you could just put it beside your project output files first to test it) and then WebView2 browser started to function as expected. Microsoft error messages sometimes (at least in my case) was a little bit misleading and did not convey enough and to the point information. – amirfg May 18 '22 at 07:56
  • I received "BadImageFormatException" that normally occurs when you mix platform targets (for example using a dll file compiled in X64 in an application that targeted for x86 or vice versa) or mix native code and .NET but that was not my problem at all. I hope this help one who may stuck in. – amirfg May 18 '22 at 07:57

1 Answers1

88

Make sure that you are not having 32-bit / 64-bit conflict.

Refer this question:

Troubleshooting BadImageFormatException

If you're running on a 64-bit OS, the Assembly RevitAPI may be compiled as 32-bit and your process as 64-bit or "Any CPU".

Or, the RevitAPI is compiled as 64-bit and your process is compiled as 32-bit or "Any CPU" and running on a 32-bit OS.

Community
  • 1
  • 1
Freelancer
  • 9,008
  • 7
  • 42
  • 81
  • 2
    Awesome! Took several tries, but finally enabled Configuration Manager and changed Target Platform (Release) to Any CPU. Thanks for your help! – m00nbeam360 Apr 10 '13 at 05:28
  • Got the problem in a new solution and tried Any CPU again without success. Any other tips? – m00nbeam360 Apr 11 '13 at 07:24
  • 3
    I had to go into the actual projects individually and check that they were set to any CPU – Fatlad Aug 05 '13 at 21:43
  • I had a similar error. I could solve it by adding the ucrtbase(d).dll and vcruntime140(d).dll into the directory of the executable. You can find more information here: http://blogs.msdn.com/b/vcblog/archive/2015/03/03/introducing-the-universal-crt.aspx – Peter Ittner Jan 21 '16 at 09:43