.net 混合模式程序集是针对运行时的“v2.0.50727”版本构建的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6425707/
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 version ‘v2.0.50727′ of the runtime
提问by Christina Wong
I'm getting the following exception:
我收到以下异常:
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 运行时中加载。
as I was trying to export crystal report from my WPF program...
当我试图从我的 WPF 程序中导出水晶报告时......
I have added the following in the app.config already...
我已经在 app.config 中添加了以下内容...
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
Any experts can help????
有高手可以帮忙吗???
Reference I found: http://www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime
我发现的参考:http: //www.davidmoore.info/2010/12/17/running-net-2-runtime-applications-under-the-net-4-runtime
回答by Talha
Try to use this exact startup tag in your app.config under configuration node
尝试在配置节点下的 app.config 中使用此确切的启动标记
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<requiredRuntime version="v4.0.20506" />
</startup>
回答by Bibaswann Bandyopadhyay
The exception clearly identifies some .NET 2.0.50727 component was included in .NET 4.0. In App.config file use this:
该异常清楚地表明 .NET 4.0 中包含了一些 .NET 2.0.50727 组件。在 App.config 文件中使用这个:
<startup useLegacyV2RuntimeActivationPolicy="true" />
It solved my problem
它解决了我的问题
回答by Brijesh Kumar Tripathi
Please add attribute useLegacyV2RuntimeActivationPolicy="true" in your applications app.config file.
请在您的应用程序 app.config 文件中添加属性 useLegacyV2RuntimeActivationPolicy="true"。
Old Value
旧值
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
New Value
新价值
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup>
It will solve your problem.
它会解决你的问题。
回答by atconway
I actually had this identical issue with the inversesolution. I had upgraded a .NET project to .NET 4.0 and then reverted back to .NET 3.5. The app.config in my project continued to have the following which was causing the above error in question:
我实际上在逆解中遇到了同样的问题。我已将 .NET 项目升级到 .NET 4.0,然后又恢复到 .NET 3.5。我的项目中的 app.config 继续具有以下导致上述错误的问题:
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
The solution to solve the error for this was to revert it back to the proper 2.0 reference as follows:
解决此错误的解决方案是将其恢复为正确的 2.0 参考,如下所示:
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
So if a downgrade is producing the above error, you might need to back up the .NET Framework supported version.
因此,如果降级导致上述错误,您可能需要备份 .NET Framework 支持的版本。
回答by Alexander Tytarchuk
Try to use another config file (not the one from your project) and RESTART Visual Studio:
尝试使用另一个配置文件(不是您项目中的配置文件)并重新启动 Visual Studio:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine.x86.exe.config
(32-bit)
or
或者
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine.exe.config
(64-bit)
回答by Talha Imam
Enabling the legacy from app.config didn't work for me. For unknown reasons, my application wasn't activating V2 runtime policy. I found a work around here.
从 app.config 启用旧版对我不起作用。由于未知原因,我的应用程序没有激活 V2 运行时策略。我在这里找到了一份工作。
Enabling the legacy from app.config is a recommended approach but in some cases it doesn't work as expected. Use the following code with in your main application to force Legacy V2 policy:
从 app.config 启用旧版是推荐的方法,但在某些情况下它不会按预期工作。在您的主应用程序中使用以下代码来强制 Legacy V2 策略:
public static class RuntimePolicyHelper
{
public static bool LegacyV2RuntimeEnabledSuccessfully { get; private set; }
static RuntimePolicyHelper()
{
ICLRRuntimeInfo clrRuntimeInfo =
(ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(
Guid.Empty,
typeof(ICLRRuntimeInfo).GUID);
try
{
clrRuntimeInfo.BindAsLegacyV2Runtime();
LegacyV2RuntimeEnabledSuccessfully = true;
}
catch (COMException)
{
// This occurs with an HRESULT meaning
// "A different runtime was already bound to the legacy CLR version 2 activation policy."
LegacyV2RuntimeEnabledSuccessfully = false;
}
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("BD39D1D2-BA2F-486A-89B0-B4B0CB466891")]
private interface ICLRRuntimeInfo
{
void xGetVersionString();
void xGetRuntimeDirectory();
void xIsLoaded();
void xIsLoadable();
void xLoadErrorString();
void xLoadLibrary();
void xGetProcAddress();
void xGetInterface();
void xSetDefaultStartupFlags();
void xGetDefaultStartupFlags();
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void BindAsLegacyV2Runtime();
}
}
回答by ToolmakerSteve
If the error happens with error column "File" as SGEN, then the fix needs to be in a file sgen.exe.config, next to sgen.exe. For example, for VS 2015, create C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\sgen.exe.config. Minimum file contents: <configuration><startup useLegacyV2RuntimeActivationPolicy="true"/></configuration>
如果错误与错误栏中的“文件”作为SGEN发生,然后修复需要在一个文件中sgen.exe.config,旁边sgen.exe。例如,对于 VS 2015,创建C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\sgen.exe.config. 最小文件内容:<configuration><startup useLegacyV2RuntimeActivationPolicy="true"/></configuration>
Source: SGEN Mixed mode assembly
来源:SGEN 混合模式组件
回答by Janis S.
For me this was thrown when running unit tests under MSTest(VS2015). Had to add
对我来说,这是在MSTest(VS2015)下运行单元测试时抛出的。不得不添加
<startup useLegacyV2RuntimeActivationPolicy="true">
</startup>
in
在
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TE.ProcessHost.Managed.exe.config
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TE.ProcessHost.Managed.exe.config

