Could Not Load File or Assembly ... an Attempt Was Made to Load a Program With an Incorrect Format (System.Badimageformatexception)

Could not load file or assembly ... An attempt was made to load a program with an incorrect format (System.BadImageFormatException)

I am pretty sure you're having a 32-bit / 64-bit conflict. It sounds like your main project might be set to 32-bit while the class its referencing is set to 64-bit. Try looking at this SO question and this one too. Between the two of them, you should be able to figure out your problem.

BadImageFormatException Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format

As mentioned already it is due to wrong architecture either
a) Using x64 assembly with Windows x86
b) Using x86 assembly with x64 process or viceversa

For best results, ensure all .NET assemblies are built with "Any CPU", and same .NET profile (ie all using .NET Core, or Client Profile or Full .NET).

...or one dependency not being found at all, Enable Fusion Log to tell where is looking to gather the assemblies:

See How to enable assembly bind failure logging (Fusion) in .NET
and
http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx

UPDATE: Given the error code 0x8007000b I am pretty sure is an architecture mismatch:
a) The dll may be Full .NET code, but not compiled with AnyCPU
b) The dll may be native code, and then you need a matching architecture (plus some calling its code using PInvoke)
c) The dll may be C++ CLI (mix of native/.NET code, again with wrong architecture).
d) The dll may be corrupt.

You may need to contact the 3rd party provider for support.
Also, this link mentions it could be a mismatch of .NET version.

Anyway, looks like the problem is narrowed.

Also if the DLL is partly native, it may need the MSVC runtime (as this question's answers mentions, Using 32-bit dll on 64-bit system shows 0x8007000B Error)

In that case the problem would be a dependency of dcasdk not being found.
You can check which Dependency Walker, see http://www.dependencywalker.com/
(it also has a profile mode where you profile an exe, and see the call to open a dll which failed at runtime).

Could not load file or assembly 'xxx' or one of its dependencies. An attempt was made to load a program with an incorrect format

Sounds like one part of the project is being built for x86-only while the rest is being built for any CPU/x64. This bit me, too. Are you running an x64 (or uh... IA64)?

Check the project properties and make sure everything is being built for "Any CPU". f you're in Visual Studio, you can check for everything by going to the "x86" or "Any CPU" menu (next to the "Debug"/"Release" menu) on the toolbar at the top of the screen and clicking "Configuration Manager..."

System.BadImageFormatException: 'Could not load file or assembly

The problem was solved.
I should not use the 64-bit version, I should use the 32-bit version.

C# CLR Excecption BadImageFormatException: Could not load file or assembly

You should change Platform target to "X86" here
Sample Image



Related Topics



Leave a reply



Submit