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

后端 未结 17 962
死守一世寂寞
死守一世寂寞 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:03

    The above didnt work for me (I am working on a web app) - but this did...

    Edit the sgen.exe.config file in the folder (I had to create one first); C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (There is also one in v7.0 folder, but I didnt need to change that one, I am using VS2012)

    The conents of the XML should look like this (same in previous answers)

    <?xml version ="1.0"?>
    <configuration>
        <startup useLegacyV2RuntimeActivationPolicy="true">
            <requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
        </startup>
    </configuration>
    
    0 讨论(0)
  • 2020-11-22 09:06

    I was experiencing this same error, and spent forever adding the suggested startup statements to various config files in my solution, attempting to isolate the framework mismatch. Nothing worked. I also added startup information to my XML schemas. That didn't help either. Looking at the actual file that was causing the problem (which would only say it was "moved or deleted") revealed it was actually the License Compiler (LC).

    Deleting the offending licenses.licx file seems to have fixed the problem.

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

    Depending on what version of the framework you're targeting, 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 targeting .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>
    
    0 讨论(0)
  • 2020-11-22 09:08

    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 :).

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

    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.

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

    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>
    
    0 讨论(0)
提交回复
热议问题