I have a C# solution, two projects, a winforms and a dll, where the winforms project references to the dll, and I've set everything I know of in the project to the framework version 2.0, yet I still get this FileLoadException on startup:
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.
The settings I configured are:
- Properties - Target framework is .NET framework 2.0
- All references the project links to are built with .NET 2.0
- All checkboxes in the Configuration manager indicating whether the projects should be built are checked.
Also I've tried cleaning the solution, deleting the map project\bin\, but when the solution is recompiled and run, the exception is still thrown. On my machine I have Visual Studio 2010 Ultimate with both .NET 4.0 and .NET 3.5 SP1 installed.
I must have missed a setting wh开发者_Go百科ich causes this exception, but I'm unaware of it, does anyone know ? I just want it to use .NET 2.0, not .NET 4.0.
To try to force it to load in CLR 2.x, you may need to have (in your app.config file):
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
This is generally only required when you have mixed-mode, and forces the hand of the loader.
Well, it's running the 4.0 CLR in spite of your efforts to target 2.0. It's bitching about a C++/CLI assembly, presumably the DLL that you referenced. A .config file is required to convince the CLR that it is okay to use .NET 4.0 to load that DLL, even though it might contain unmanaged code that expects 2.0 to be used, google "useLegacyV2RuntimeActivationPolicy". That would solve the 4.0 loading problem for that DLL.
About the only other reason that it could still load 4.0 is a .config file that says it should use 4.0, <supportedRuntime>
element. To make this more visual you can use the Fuslogvw.exe tool, set it up to log all bindings. Copy/paste the binding trace for your EXE into your question if you can't make sense of it.
精彩评论