Use .Net 2.0 dll in .net 4.0 wpf application

I am trying to add a link to the .Net 2.0 DLL in a WPF application designed for the .NET Framework.

I added <startup useLegacyV2RuntimeActivationPolicy="true"> to the app.config file. The WPF application works fine, but when trying to access the DLL.Net 2.0 receives a BadImageFormatException error message at runtime.

"An attempt was made to download a program with the wrong format"

This works with the new WPF test project, but does not work in my application. My application uses Entity Framework and MEF. Can these technologies cause a problem?

Any ideas?

Edit: Allowed

According to Alois's comment below, I had a main application oriented to β€œAny processor”, and the DLL was aimed at the 32-bit version.

<startup useLegacyV2RuntimeActivationPolicy="true"> not required

+7
source share
1 answer

When you need to use the useLegacyV2RuntimeActivationPolicy attribute, you are working with a mixed-mode assembly that was written in C ++ / CLI and targeting version 2.0.50727 from the CLR. Such an assembly contains both managed code and native machine code. This machine code is 32-bit in your case; you cannot run it in 64-bit mode. This is an exception. Requires installation of an x86 platform target platform in an EXE project.

+2
source

All Articles