0

I have a class library project, I have to reference an assembly in my class library project which targets v2.0.50727, then ultimately calling my class library from a project which is using .Net 4 version.

When the application runs, it gives 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.”

I know i can add attributes in app.config to avoid this error, but in my case, this is class library which has no app.config.

I tried changing my class library to .net framework 2, but it is still showing error.

When I change target framework of main application from .net 4 to .net 3.5, compiler gives error on following line:

using System.ComponentModel.Composition;

What should I do ?

alphaprolix
  • 601
  • 2
  • 10
  • 25
  • You must supply a .config file for the EXE that uses your class library. Getting this mixed-mode assembly rebuilt to target .NET 4 is very trivial. There's a programmer somewhere that needs 5 minutes to do this for you, you will not find him here. Pick up the phone and give him a call. – Hans Passant Dec 23 '13 at 12:13
  • Hmm, in my case it is Microsoft, and the EXE i am using is Microsoft Dynamics AX Retail POS, cant call them, it won't work, may be I have to convert my program to an exe and call it as external program from MS POS :( – alphaprolix Dec 23 '13 at 12:24

1 Answers1

0

I ended up with changing my DLL to form-less winform EXE file which can accept command line arguments to replicate class library constructor arguments functionality. I supplied following attributes in my exe app.config file to avoid mixed mode assembly error:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
alphaprolix
  • 601
  • 2
  • 10
  • 25