49

i've included a directX player in c# .net 4.0 app that is included here ( answer2 ) . The problem is that when i try to initialize the object ( i.e. Player mPlayer=new Player()) this error occurs :

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

Anyone knows what it can be?

Alex
  • 10,869
  • 28
  • 93
  • 165
  • IMPORTANT: If the error happens with error column "File" as `SGEN`, then the fix needs to be in a file `sgen.exe.config`, next to `sgen.exe`. For example, for VS 2015, create `C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\sgen.exe.config`. Source: [SGEN Mixed mode assembly](https://support.microsoft.com/en-us/help/2572158/sgen-mixed-mode-assembly-is-built-against-version-v2-0-50727-of-the-ru) Minimum file contents: `` – ToolmakerSteve Oct 06 '17 at 01:19

3 Answers3

72

The way I fixed this error was by changing the 'configuration' node on my app.config from this:

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

to this:

<startup useLegacyV2RuntimeActivationPolicy="true">
   <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
Gustavo Mori
  • 8,319
  • 3
  • 38
  • 52
  • 9
    Thanks for further clarifying for those of us who don't modifiy the app.config xml file enough to know how to set that value to true. +1 – Jacklynn Jan 01 '13 at 01:29
  • My pleasure, Jack. At the time, I had to look for that myself, so I figured someone out there could use that extra bit of info as well :) – Gustavo Mori Jan 07 '13 at 04:54
  • The solution above has worked in every case where I have encountered this problem prior to today. In case anyone finds themselves with an inherited project wherein this DOES NOT work, and you know that it should, be sure to check "Copy to Output Directory" for App.Config = Always or Newer, or you'll be frustrated. – El-Ahrairah Jan 23 '19 at 04:11
70

You need to add an app.Config file and set useLegacyV2RuntimeActivationPolicy to true.

This is required to use mixed mode CLR 2 assemblies in a .NET 4 application.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • 3
    @Badescu Got curious about that as well, here's a link explaining: http://msdn.microsoft.com/en-us/library/x0w2664k.aspx – Badaro Oct 25 '10 at 21:28
  • 1
    Thank you!!!! This is the weirdest problem I'd ever encountered. In VS 2012 .Net 4.0 my application would just hang the moment I initialized any variable of a type related to this DLL. I'd never seen anything like it. Couldn't find anything about the problem until I found this! – Quinxy von Besiex Dec 22 '12 at 16:33
  • Please excuse my ignorance but I get the same problem. My question is where do you actually create the app.config file ? I've seen the same tag mentioned in the article in the file 'dcexec.exe.config' but changing it here, and restarting the server, has no effect. – Neil Mar 24 '14 at 12:45
  • @Neil It's in the main executable's app.config file. It has to sit next to the exe you're running, with the same name, etc. – Reed Copsey Mar 24 '14 at 16:52
  • @ReedCopsey Though in the typical Visual Studio project setup, there is a file named exactly "app.config", in project's top folder (next to C# .csproj or VB .vbproj file), which Visual Studio copies, to become the main executable's "myprojectname.exe.config". At least that is what I see in VS 2010. Tried it today for both C# and VB, WinForm apps. – ToolmakerSteve Apr 15 '14 at 19:16
4

Here is possible assembly configuration:

<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
</configuration>
Mykola
  • 3,343
  • 6
  • 23
  • 39
Mohammad Atiour Islam
  • 5,380
  • 3
  • 43
  • 48