我有一个项目,我想在其中使用一些。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运行时加载 配置信息。
需要什么“额外配置”?
当前回答
通过添加带有“useLegacyV2RuntimeActivationPolicy”属性集的“startup”元素能够解决这个问题。
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
但是必须将它作为App.config中configuration标签的第一个子元素才能生效。
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
......
....
其他回答
我也遇到过同样的错误,花了很长时间将建议的启动语句添加到我的解决方案中的各种配置文件中,试图隔离框架不匹配。毫无效果。我还向XML模式添加了启动信息。这也无济于事。查看导致问题的实际文件(只会说它被“移动或删除”),发现它实际上是许可编译器(LC)。
删除有问题的license。Licx文件似乎已经解决了这个问题。
这取决于你的目标框架的版本,你可能想看看这里得到正确的字符串:
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>
这个论坛贴在。net框架开发者中心。这可能会提供一些见解。
(添加到应用程序的配置文件中。)
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
同时使用2.0和4.0程序集并不是很简单。
在app.config中支持的框架声明的ORDER实际上对混合模式抛出的异常有影响。如果你颠倒声明顺序,你会得到混合模式错误。这就是我回答这个问题的目的。
如果你在Windows窗体应用程序中遇到错误,试试这个,大多数是Windows窗体应用程序。
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
<supportedRuntime version="v2.0.50727"></supportedRuntime>
</startup>
或者项目不是Windows窗体。在Web项目中,将此添加到Web。配置文件。
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<supportedRuntime version="v2.0.50727"></supportedRuntime>
</startup>
经过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.