Wednesday, February 23, 2011

BadFormatException / FileLoadException

Today I had an issue where an application was throwing "BadFormatException" on a 64bit machine and on a 32bit machine "FileLoadException".

The exception message was:

Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

Although I've seen this before and new it was because by default .NET will not let you mix different versions of the runtime in multiple dependencies, it took me a few moments to google it. So I thought I'd put it here for quick reference. For example, if you are referencing a 2.0 DLL from a 4.0 application by default you will get an exception the first time you try to access the 2.0 DLL. Unless you choose to allow multiple run-times.

Add the following to your app.config:
 <startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>

No comments:

Post a Comment