none
Mxed mode dll unable to load in .net 4.0

    Question

  • I am currently facing an issue where a mixed mode dll is unable to load in .net 4.0 when invoked dynamically. I am getting the following exception:

    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 got to know that adding a config file with the follwoign info in the app would help:
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
      </startup>
    </configuration>

    Now, the issue is, this dll can be used by many apps in Dev10. I need some mechanism to add config file with the dll, so that it works whenever the dll get loaded.
    Is there a way to have dll.config file?

    • Changed type nobugzMVP, Moderator Wednesday, August 05, 2009 11:37 AM No addition info expected, marking answered
    Thursday, July 30, 2009 5:57 AM

Answers

  • There is not, every .exe will need that .config file.  Why don't you just rebuild that assembly?

    Hans Passant.
    Thursday, July 30, 2009 11:23 AM
    Moderator

All replies

  • There is not, every .exe will need that .config file.  Why don't you just rebuild that assembly?

    Hans Passant.
    Thursday, July 30, 2009 11:23 AM
    Moderator
  • We are changing the issue type to “Comment” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by editing your initial post and changing the radio button at the top of the post editor window. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions, thank you!

     

    Thanks,

    Eric


    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    Wednesday, August 05, 2009 10:17 AM
  • I am developing inside VSTO and the main issue is that if I enable this config switch at Process level is this likely to have an impact to any applications that are written with .NET4. is there a way that the Appdomain could have this switch enabled?

    Regards
    Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers !
    Monday, December 07, 2009 4:38 PM
  • Please do not reopen this thread, ask a new question instead.

    This is by design set per process. If it was not per process, then CLR wouldn't know which CLR version in process to use when a mixed-mode assembly calls into managed code when the thread is native and doesn't have any AppDomain state yet.

    Thanks,
    -Karel
    Monday, December 07, 2009 7:10 PM
    Moderator
  • Hi,

    I made the updates to the app configuration file, both for the assembly, and the exe projects, rebuilding and running the project still results in the runtime error. Trying the config update only for the dll and not the remianing projects results in the same outcome. Any other suggestions of what the correction is. By the way, the application was running on VS2008, and now it is ported to the VS2010 RC1.

    Regards,

    Reza Bemnian, PhD
    Monday, February 15, 2010 6:05 PM
  • Hi,

    The only way the app config updates worked for me was to add it both to the dll assembly and the project using the dll. Also, I had to use the following config update. This is done on a VS2008 project ported to VS2010 RC1.

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

    I hope it helps
    Reza Bemanian, PhD

    • Proposed as answer by erictummers Thursday, January 06, 2011 3:33 PM
    Monday, February 15, 2010 8:03 PM
  • Anywhy thanks for your 

     

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

    Friday, May 14, 2010 3:46 AM
  • <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
    </startup>

     

     

    please where  is config

    Monday, July 26, 2010 10:03 PM
  • It's YourApp.exe.config file sitting next to the EXE that starts your process.

    -Karel

    Tuesday, July 27, 2010 5:03 PM
    Moderator
  • Hi,

    Similar issue, so I thought I'd follow up on the same question. I have a VSTO application that's on 4.0 client profile. I need to use SQLite library (http://sqlite.phxsoftware.com/) and I keep getting the mixed mode assembly issue.

    I already have this on the VSTO project's app.config

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

    So, I'm not sure what's missing. Any help please?

    Wednesday, October 20, 2010 11:29 AM
  • When i try this fix my entity framework connection fails to succeed. (EF 4.0)

    Any hints ???

    • Proposed as answer by pony88 Wednesday, October 26, 2011 9:13 AM
    • Unproposed as answer by pony88 Wednesday, October 26, 2011 9:13 AM
    Tuesday, August 09, 2011 9:43 PM
  • The ideal answer is SAP/Crystal release a built assembly for .NET4 for these database drivers alternatively we created a separate .EXE that was used to run the reporting and this would have a config file to run in a compliant mode for the mixed assemblies ie;

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

    This needs to be in the "Runreports.exe.config" file and the runreports.exe is configured to use remoting to transfer the data from the calling VSTO application into the RunReports.exe program.

    The above is a lot of plumbing but will work without having to effect a "WINWORD.EXE.CONFIG" or any other outlook/excel etc etc config file being created in the Office program files location. The main thing to note that adding the CONFIG file for the Office application doesn't help other vendors who may expect to be able to run .NET 4 side by side.

    Regards


    Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers ! Owner and CTO FWBS Ltd http://www.fwbs.net Twitter: www.twitter.com/mikewalker74
    Wednesday, October 26, 2011 9:26 AM
  • I think the error occurs is because you had convert  your project from .Net 2.0(vs 2005) to .Net4.0 (vs 2010).

    Step1 : You need to modify your app.config file to include :

    Step 2 : check all *.dll of your projects.

    • If the dll does have "Runtime Version is v2.0.5..." but never used, you had remove it.
    • If this dll is used, you must delete and re-add it.

    Thanks and regards. wish success.

    Wednesday, October 26, 2011 9:35 AM
  • Mixed mode assemblies are still mixed and will cause an issue if not compiled for the correct version of .NET... Crystal Reports is a good example and in VSTO the CONFIG switch is process sensitive so has further issues to be reviewed as per my previous post.
    Mike Walker MVP - Visual Developer VSTO - Please mark the best replies as Answers ! Owner and CTO FWBS Ltd http://www.fwbs.net Twitter: www.twitter.com/mikewalker74
    Wednesday, October 26, 2011 10:33 AM
  • try to remove this part from app.config :

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

    it will work , !

    Saturday, February 18, 2012 1:34 PM
  • 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.


    ~ Loveson

    • Proposed as answer by R Kipling Monday, April 23, 2012 2:33 PM
    Monday, April 23, 2012 2:33 PM
  • thanks R  kipling really its works

    thanks

    Saturday, July 07, 2012 10:34 AM