Home : WingScan : Cause of System.BadImageFormatException
Q10165 - FAQ: Cause of System.BadImageFormatException
When deploying an application, you might run into this error:

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

"BadImageFormat" is referring to the format of the dll, it means .Net tried to load a 64-bit assembly in to a 32-bit process or vice-versa. Typically this will happen on a 64-bit machine when building targeting AnyCPU. AnyCPU marks your output assembly/executable as being able to run under either x86/x64 and it is determined which at runtime. If the assemblies it finds at runtime don't match the CPU target (x86/x64) it is running in it fails with that error.

To resolve this error you need to ensure the references you've included in your project and are present in your /bin/ folder are the same CPU target as your application is running.

The simplest general case for executable applications is to target x86 and include the x86 Atalasoft references. As 32-bit applications run correctly under both 32-bit and 64-bit systems it simplifies building and deployment. However, leaving your application as AnyCPU will work as long as you deploy the correct CPU target assemblies for each deployed machine.

For web projects that will be deployed in IIS, you should leave the project to AnyCPU, as IIS expects 64-bit assemblies on a 64-bit server and requires AppPool configuration to allow 32-bit assemblies.

Note: If you are receiving this error currently, after correcting your references ensure you run a 'clean' on the project or manually remove the Atalasoft assemblies from your /bin/ folder. Visual Studio will not remove the incorrect references from your /bin/ without this step.

In Visual Studio you can set your project target using the "Configuration Manager"

x86: 32bit only
x64: 64bit only
Any CPU: let .Net choose at runtime

For more information, please see:

Q10149 - INFO: Compiling with DotImage on a 64-bit system

Q10406 - FIX: Drag-Drop of Some Atalasoft Viewers Not Adding Control to Designer

Q10341 - INFO: Workaround for a license compiler exception on 64-bit systems with VS2010 .Net 4.0

Q10288 - INFO: Workaround for a license compiler exception on 64-bit systems with VS2008/VS2010 .Net 2.0

Q10158 - INFO: Warning:Referenced assembly targets a different processor

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved