我有一个项目,我想在其中使用一些。net 4.0的功能,但核心要求是我可以使用System.Data.SQLite框架,它是针对2.X编译的。我看到提到这是可能的,比如这里接受的答案,但我不知道如何实现这一点。
当我只是试图运行我的4.0项目,同时引用2。我得到:
混合模式程序集是根据运行时版本“v2.0.50727”构建的 并且不能在4.0运行时加载 配置信息。
需要什么“额外配置”?
我有一个项目,我想在其中使用一些。net 4.0的功能,但核心要求是我可以使用System.Data.SQLite框架,它是针对2.X编译的。我看到提到这是可能的,比如这里接受的答案,但我不知道如何实现这一点。
当我只是试图运行我的4.0项目,同时引用2。我得到:
混合模式程序集是根据运行时版本“v2.0.50727”构建的 并且不能在4.0运行时加载 配置信息。
需要什么“额外配置”?
当前回答
上面的方法对我没用(我正在开发一个web应用程序)——但是这个方法有用……
编辑文件夹中的sgen.exe.config文件(我必须先创建一个); C:\Program Files (x86)\Microsoft sdk \Windows\v8.0A\bin\NETFX 4.0工具 (也有一个在v7.0文件夹,但我不需要改变,我使用VS2012)
XML的内容应该如下所示(与前面的回答相同)
<?xml version ="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
</startup>
</configuration>
其他回答
经过3-4小时的谷歌搜索,我找到了解决这个问题的方法。我添加了以下内容
<startup selegacyv2runtimeactivationpolicy="true">
<supportedruntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
If this doesn't solve your problem then--> In the Project References Right Click on DLL where you getting error --> Select Properties--> Check the Run-time Version --> If it is v2.0.50727 then we know the problem. The Problem is :- you are having 2.0 Version of respective DLL. Solution is:- You can delete the respective DLL from the Project references and then download the latest version of DLL's from the corresponding website and add the reference of the latest version DLL reference then it will work.
我在升级到Visual Studio 2015时遇到了这个问题,这里发布的解决方案都没有任何区别,尽管配置是正确的,但更改的位置不是。我通过添加以下配置修复了这个问题:
<startup useLegacyV2RuntimeActivationPolicy="true">
</startup>
到:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TE.ProcessHost.Managed.exe.config
然后重启Visual Studio。
这取决于你的目标框架的版本,你可能想看看这里得到正确的字符串:
http://msdn.microsoft.com/en-us/library/ee517334.aspx
我浪费了很多时间试图弄清楚为什么我针对。net 4.0客户端发布的版本需要完整版本。 最后我用了这个:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"
sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
如果您在web服务中工作,v2.0程序集是由WcfSvcHost.exe加载的依赖项,则必须包含
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
在. .\Microsoft Visual Studio 10.0\Common7\IDE\ WcfSvcHost.exe.config文件
这样,Visual Studio就能够在运行时通过加载器发送正确的信息。
为了使用CLR 2.0混合模式程序集,您需要修改App.Config文件以包括:
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
关键是useLegacyV2RuntimeActivationPolicy标志。这将导致CLR使用最新版本(4.0)加载混合模式程序集。没有这一点,它就不会起作用。
注意,这只对混合模式(c++ /CLI)程序集有影响。你可以加载所有托管的clr2程序集,而不需要在app.config中指定。