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

后端 未结 17 884
死守一世寂寞
死守一世寂寞 2020-11-22 08:20

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

相关标签:
17条回答
  • 2020-11-22 09:12

    Add following at this location C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64 FileName: sgen.exe.config(If you dont find this file, create and add one)

     <?xml version ="1.0"?>
    
    <configuration>
     <runtime>        
            <generatePublisherEvidence enabled="false"/>    
        </runtime>
    
        <startup useLegacyV2RuntimeActivationPolicy="true">
    
                    <supportedRuntime version="v4.0" />
    
        </startup>    
    
    </configuration>

    Doing this resolved the issue

    0 讨论(0)
  • 2020-11-22 09:14

    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>
    
    0 讨论(0)
  • 2020-11-22 09:14

    I had this problem when upgrading to Visual Studio 2015 and none of the solutions posted here made any difference, although the config is right the location for the change is not. I fixed this issue by adding this configuration:

    <startup useLegacyV2RuntimeActivationPolicy="true">
    </startup>
    

    To: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TE.ProcessHost.Managed.exe.config

    Then restarted Visual Studio.

    0 讨论(0)
  • 2020-11-22 09:14

    Also i had this issue with the class library, If any one have the issue with the class library added to your main application. Just add

    <startup useLegacyV2RuntimeActivationPolicy="true">
    

    to you main application which would then be picked by the class library.

    0 讨论(0)
  • 2020-11-22 09:15

    Was able to solve the issue by adding "startup" element with "useLegacyV2RuntimeActivationPolicy" attribute set.

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

    But had to place it as the first child element of configuration tag in App.config for it to take effect.

    <?xml version="1.0"?>
      <configuration>
        <startup useLegacyV2RuntimeActivationPolicy="true">
          <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
          <supportedRuntime version="v2.0.50727"/>
        </startup>
      ......
    ....
    
    0 讨论(0)
提交回复
热议问题