C# 混合模式程序集是针对“v2.0.50727”错误构建的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14815076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mixed mode assembly is built against 'v2.0.50727' error
提问by ganders
First of all, I've found the other posts on StackOverflow here, but it did not resolve my error.
首先,我在这里找到了 StackOverflow 上的其他帖子,但它没有解决我的错误。
I have 3 different environments/domains with a build server in each location. My Dev and UAT environments build just fine, but the production version does not work.
我有 3 个不同的环境/域,每个位置都有一个构建服务器。我的 Dev 和 UAT 环境构建得很好,但生产版本不起作用。
I'm getting the error
我收到错误
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
混合模式程序集是针对运行时的“v2.0.50727”版本构建的,如果没有附加配置信息,则无法在 4.0 运行时中加载
I've added this tag to my app.config file (which was the suggested fix in the link I have above)
我已将此标记添加到我的 app.config 文件中(这是我上面链接中建议的修复程序)
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
What else could be different between my build servers/environments/domains that would be causing this issue?
我的构建服务器/环境/域之间还有什么可能会导致此问题?
In response to Allen's question, I believe this is what you're asking:
在回答艾伦的问题时,我相信这就是你要问的:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D3D87C05-2811-489B-9F0D-7676B6485AA0}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MVST.Batch.CorrespondenceConversion</RootNamespace>
<AssemblyName>MVST.Batch.CorrespondenceConversion</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
I have over 100 other projects that are setup the exact same way and those build ok.
我还有 100 多个其他项目,它们的设置方式完全相同,并且构建正常。
采纳答案by smily
http://support.microsoft.com/kb/2572158
http://support.microsoft.com/kb/2572158
Add the verbiage useLegacyV2RuntimeActivationPolicy="true"
below either to either of the following locations:
将useLegacyV2RuntimeActivationPolicy="true"
下面的措辞添加到以下任一位置:
- sgen.exe.config file located at the following location: ..\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\
- The applications' app.config file
- sgen.exe.config 文件位于以下位置:..\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\
- 应用程序的 app.config 文件
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
回答by ganders
Here's the fix that worked...still not sure why my project needed to be 2.0 whereas others (in the link in my question) needed to be 4.0.
这是有效的修复...仍然不确定为什么我的项目需要 2.0 而其他项目(在我的问题中的链接中)需要 4.0。
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
回答by Codeman
If you're running in 64-bit, you may have to add it to the Visual Studio test engine config:
如果您在 64 位上运行,则可能需要将其添加到 Visual Studio 测试引擎配置中:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine.exe.config
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine.exe.config
Add the startup node like so:
像这样添加启动节点:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<requiredRuntime version="v4.0.20506" />
</startup>
回答by Roberto
In the case of unit tests, should you be using Resharper for your unit tests, then you already know none of the other answers have worked for you.
在单元测试的情况下,如果您使用 Resharper 进行单元测试,那么您已经知道其他答案都不适合您。
Resharper launches the ResharperTestRunner (either 32 or 64 bits) in order to execute your unit tests. This file is located (at least in my system) under C:\Users[user]\AppData\Local\JetBrains\Installations\ResharperPlatform[version]. The configuration of this file should be at the same location and should have the same name, but with a .config suffix. In my system, it wasn't there. So, I created it and added this:
Resharper 启动 ResharperTestRunner(32 位或 64 位)以执行您的单元测试。该文件位于(至少在我的系统中)在 C:\Users[user]\AppData\Local\JetBrains\Installations\ResharperPlatform[version] 下。该文件的配置应该在相同的位置并且应该具有相同的名称,但是带有 .config 后缀。在我的系统中,它不存在。所以,我创建了它并添加了这个:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<!-- 4.0 RTM -->
<supportedRuntime version="v4.0.30319"/>
<!-- 2.0 RTM -->
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
Then, my tests started to work. Hope this helps.
然后,我的测试开始工作。希望这可以帮助。