Skip to main content

What "additional configuration" is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?


I have a project in which I'd like to use some of the .NET 4.0 features but a core requirement is that I can use the System.Data.SQLite framework which is compiled against 2.X. I see mention of this being possible such as the accepted answer here but I don't see how to actually achieve this.



When I just try and run my 4.0 project while referencing the 2.X assembly I get:




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.



What "additional configuration" is necessary?


Source: Tips4allCCNA FINAL EXAM

Comments

  1. In order to use a CLR 2.0 mixed mode assembly, you need to modify your App.Config file to include:

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


    The key is the useLegacyV2RuntimeActivationPolicy flag. This causes the CLR to use the latest version (4.0) to load your mixed mode assembly. Without this, it will not work.

    Note that this only matters for mixed mode (C++/CLI) assemblies. You can load all managed CLR 2 assemblies without specifying this in app.config.

    ReplyDelete
  2. This forum post on the .NET Framework Developer Center. It might provide some insight.

    (Add to the app's config file.)

    <configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
    </startup>
    </configuration>

    ReplyDelete
  3. Depending on what version of the framework you're targetting, you may want to look here to get the correct string:

    http://msdn.microsoft.com/en-us/library/ee517334.aspx

    I wasted hours trying to figure out why my release targetting .Net 4.0 client required the full version.
    I used this in the end:

    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0.30319"
    sku=".NETFramework,Version=v4.0,Profile=Client" />
    </startup>

    ReplyDelete
  4. I used this config:

    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v2.0"/>
    <supportedRuntime version="v4.0"/>
    </startup>


    Worked for me

    ReplyDelete
  5. Once you set the app.config file, visual studio will generate a copy in the bin folder named App.exe.config. Copy this to the application directory during deployment. Sounds obvious but surprisingly a lot of people miss this step. WinForms developers are not used to config files :).

    ReplyDelete
  6. Using 2.0 and 4.0 assemblies together isn't quite straight forward.

    The ORDER of the supported framework declarations in app.config actually have an effect on the exception of mixed mode being thrown. If you flip the declaration order you will get mixed mode error. This is the purpose of this answer.

    So if you get the error in a Windows Forms app, , try this, mostly Windows Forms apps.

    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
    <supportedRuntime version="v2.0.50727"></supportedRuntime>
    </startup>


    Or if the project is not Windows Form. In a Web project add this to web.config file.

    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    <supportedRuntime version="v2.0.50727"></supportedRuntime>
    </startup>

    ReplyDelete
  7. Additionally, you need to add a reference to System.configuration to fix the problem stated by Dave in the comments above.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.