BadImageFormatException Occurs When Instantiating Types Defined in a Referenced Assembly at Run-time
BadImageFormatException Occurs When Instantiating Types Defined in a Referenced Assembly at Run-time
RAPID PUBLISHING
Action
Result
BadImageFormatException was unhandled
Exception Details:
System.BadImageFormatException was unhandled
Message=Could not load file or assembly ‘<Assembly Name>, Version=<Assembly Version>, Culture=<culture>, PublicKeyToken=<PublicKeyToken>’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
Cause
If your application is compiled to target a specific platform (x86 or x64), but attempts to load and execute an assembly that targets a different platform, the BadImageFormatException will occur. This behavior will also occur if your application is compiled targeting the AnyCPU platform, and then is run an operating system whose platform differs than the assembly whose type you are trying to instantiate. For example, if the main application is compiled to AnyCPU, and references an assembly that targets x86, then if you run the application on an x64 operating system, the BadImageFormatException will occur.
This behavior is by design.
Resolution
Advanced Compiler Settings Dialog Box (Visual Basic)
http://msdn.microsoft.com/en-us/library/07bysfz2.aspx (http://msdn.microsoft.com/en-us/library/07bysfz2.aspx)
/platform (Specify Output Platform) (C# Compiler Options)
http://msdn.microsoft.com/en-us/library/zekwfyz4.aspx (http://msdn.microsoft.com/en-us/library/zekwfyz4.aspx)
If you are referencing a third party component and cannot rebuild it yourself, contact the component vendor to see if a version of the assembly is available that has been compiled targeting AnyCPU. This will allow the Common Language Run-time (CLR) to Just-In-Time (JIT) compile to run as either a 32-bit or 64-bit module, depending on the machine architecture the operating system and host process are targeting.
More Information
warning CS1607: Assembly generation — Referenced assembly ‘<referenced assembly.dll>’ targets a different processor
vbc : warning BC40010: Possible problem detected while building assembly ‘<project name.exe>’: Referenced assembly ‘<referenced assembly.dll>’ targets a different processor
For more information on the limitations of process interoperability, please see the following MSDN article.
Process Interoperability
http://msdn.microsoft.com/en-us/library/aa384231(VS.85).aspx (http://msdn.microsoft.com/en-us/library/aa384231(VS.85).aspx)
DISCLAIMER
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
APPLIES TO
- Microsoft Visual Studio 2005 Professional Edition
- Microsoft Visual Studio 2005 Standard Edition
- Microsoft Visual Studio 2005 Team Suite
- Microsoft Visual Studio 2008 Professional Edition
- Microsoft Visual Studio 2008 Standard Edition
- Microsoft Visual Studio Team System 2008 Team Suite
Keywords: |
kbnomt kbrapidpub KB967163 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
Microsoft Corporation. All rights reserved. Terms of Use | Trademarks
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Back to the top
Leave a Reply