Mixed mode assembly is built against version '2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime

StackOverflow https://stackoverflow.com/questions/14508627

Pregunta

I'm using Visual Studio 2012 and the .Net Framework 4.5 I have 2 Solutions: 1) WPF Application 2) Class library (dll)

The Class Library contains 3 buttons and a control that has to be inside a WindosFormsHost control since it was made for WinForms.

The only referenced assemblies outside of the .NET Framework ones are for the aforementioned winforms control and iTextSharp.

The winforms control seems to be kinda old and when I put the reference in my dll I got the same error as the title but following other SO questions/answers, my I put this in my config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

The error:

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

As I mentioned, I've seen questions posting this issue, and they did solve the issue in my DLL project, but in the project using that DLL I've tried them all to no avail. For reference:

  1. What 'additional configuration' is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?
  2. Mixed mode assembly is built against version ‘v2.0.50727′ of the runtime
  3. What does 'useLegacyV2RuntimeActivationPolicy' do in the .NET 4 config?
  4. Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime
  5. Mixed mode assembly is built against version X and cannot be loaded in version Y of the runtime without additional configuration information

In that project my config file has the exact same tags with the same values.

Also to note, in my WPF Application, at the beginning I was getting an error about it not being able to find the specified dll (for the winforms control), in the end I put that control's dll in the GAC.

I've tried changing my target framework for all of the possibilities (4.5, 4.0 full and client, 3.5 full and client, 3.0 and 2.0), building my DLL in debug and release and setting the "Generate serialization assembly" to OFF, also, changed the platform target from Any CPU to x86 and x64. I only tried changing the value of one setting at a time.

Is this a problem in VS2012 or what do I need to do to solve this?

EDIT:

The above error is shown at design time in the errors list, the designer shows an error saying "Cannot create an instance of 'my_class'"

The inner exception of that one says: "Set connectionId threw an exception" and the inner exception of this is the title message.

This still allows the solution to be built, and upon running the application, I get basically the same, except that the innermost exception says:

"Could not load file or assembly 'SigPlusNET, Version=1.1.3358.14336, Culture=neutral, PublicKeyToken=6aef07010bb0624f' or one of its dependencies. An attempt was made to load a program with an incorrect format."

That one is the winForms control's assembly, upon inspection through dotPeek, the only dependencies it has are .NET Framework ones

¿Fue útil?

Solución

Working with Bling for DirectX 10.0, (Bling UI Toolkit at CodePlex). I got the error that ended me up here on this page looking for the solution, the app.config file in the D3D10.example included the supported runtime, version=4 line. But it does NOT include a later line for the version=2 .net line, using the app.config as:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" />
  <supportedRuntime version="v2.0.50727" />
 </startup>
</configuration>

solved the problem, and all examples run in VS2012 once the config file is modified to the code shown.

I don't know if this post is to late for an answer, I'm just starting in windows 7 and VS2012 this month on a graphics project and the config change solved my problem.

Otros consejos

This might be caused because you have 4.0 in 1 location and 4.5 in another on this line:

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

Try:

<supportedRuntime version="v4.5" sku=".NETFramework,Version=v4.5" />

or

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />

My approach was a little different. The error clearly identifies some .NET 2.0.50727 component was included in .NET 4.0 In App.config file instead of use this:

<startup useLegacyV2RuntimeActivationPolicy="true"> 

It solved my problem

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top