混合模式程序集是针对运行时的“2.0.50727"版本构建的,无法在 4.0 运行时中加载 [英] Mixed mode assembly is built against version '2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime

查看:28
本文介绍了混合模式程序集是针对运行时的“2.0.50727"版本构建的,无法在 4.0 运行时中加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Visual Studio 2012 和 .Net Framework 4.5我有 2 个解决方案:1)WPF 应用程序 2)类库(dll)

I'm using Visual Studio 2012 and the .Net Framework 4.5 I have 2 Solutions: 1) WPF Application 2) Class library (dll)

类库包含 3 个按钮和一个必须位于 WindosFormsHost 控件内的控件,因为它是为 WinForms 制作的.

The Class Library contains 3 buttons and a control that has to be inside a WindosFormsHost control since it was made for WinForms.

.NET Framework 之外唯一引用的程序集用于上述 winforms 控件和 iTextSharp.

The only referenced assemblies outside of the .NET Framework ones are for the aforementioned winforms control and iTextSharp.

winforms 控件似乎有点旧,当我将引用放入我的 dll 时,我得到了与标题相同的错误,但在其他 SO 问题/答案之后,我将其放入了我的配置文件中:

The winforms control seems to be kinda old and when I put the reference in my dll I got the same error as the title but following other SO questions/answers, my I put this in my config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

错误:

混合模式程序集是针对运行时的v2.0.50727"版本构建的,如果没有附加配置信息,则无法在 4.0 运行时中加载

正如我所提到的,我已经看到发布这个问题的问题,他们确实在我的 DLL 项目中解决了这个问题,但是在使用该 DLL 的项目中,我已经尝试了所有这些都无济于事.供参考:

As I mentioned, I've seen questions posting this issue, and they did solve the issue in my DLL project, but in the project using that DLL I've tried them all to no avail. For reference:

  1. 什么附加"在 .NET 4.0 项目中引用 .NET 2.0 混合模式程序集是否需要配置"?
  2. 混合模式组装针对运行时的v2.0.50727"版本构建
  3. useLegacyV2RuntimeActivationPolicy"在 .NET 4 中有什么作用配置?
  4. 混合模式程序集是针对运行时的v2.0.50727"版本构建的,无法在 4.0 运行时中加载
  5. 混合模式程序集是针对版本 X 构建的,如果没有附加配置信息,则无法在运行时的版本 Y 中加载

在那个项目中,我的配置文件具有完全相同的标签和相同的值.

In that project my config file has the exact same tags with the same values.

还要注意,在我的 WPF 应用程序中,一开始我收到一个错误,提示它无法找到指定的 dll(用于 winforms 控件),最后我将该控件的 dll 放在 GAC 中.

Also to note, in my WPF Application, at the beginning I was getting an error about it not being able to find the specified dll (for the winforms control), in the end I put that control's dll in the GAC.

我已经尝试为所有可能性(4.5、4.0 完整和客户端、3.5 完整和客户端、3.0 和 2.0)更改我的目标框架,在调试和发布中构建我的 DLL 并将生成序列化程序集"设置为此外,OFF 还将平台目标从 Any CPU 更改为 x86 和 x64.我一次只尝试更改一个设置的值.

I've tried changing my target framework for all of the possibilities (4.5, 4.0 full and client, 3.5 full and client, 3.0 and 2.0), building my DLL in debug and release and setting the "Generate serialization assembly" to OFF, also, changed the platform target from Any CPU to x86 and x64. I only tried changing the value of one setting at a time.

这是 VS2012 中的问题还是我需要做些什么来解决这个问题?

Is this a problem in VS2012 or what do I need to do to solve this?

上面的错误是在设计时错误列表中显示的,设计器显示的错误是Cannot create an instance of 'my_class'"

The above error is shown at design time in the errors list, the designer shows an error saying "Cannot create an instance of 'my_class'"

那个的内部异常说:Set connectionId throw an exception",这个内部异常是标题消息.

The inner exception of that one says: "Set connectionId threw an exception" and the inner exception of this is the title message.

这仍然允许构建解决方案,并且在运行应用程序时,我得到了基本相同的结果,除了最里面的异常说:

This still allows the solution to be built, and upon running the application, I get basically the same, except that the innermost exception says:

无法加载文件或程序集‘SigPlusNET,版本=1.1.3358.14336,文化=中性,PublicKeyToken=6aef07010bb0624f’或其依赖项之一.尝试加载格式不正确的程序."

那个是winForms控件的程序集,通过dotPeek检查,它唯一的依赖是.NET Framework的

That one is the winForms control's assembly, upon inspection through dotPeek, the only dependencies it has are .NET Framework ones

推荐答案

使用 Bling for DirectX 10.0,(CodePlex 的 Bling UI 工具包).我得到的错误最终导致我在此页面上寻找解决方案,D3D10.example 中的 app.config 文件包含支持的运行时,version=4 行.但它不包括 version=2 .net 行的后续行,使用 app.config 作为:

Working with Bling for DirectX 10.0, (Bling UI Toolkit at CodePlex). I got the error that ended me up here on this page looking for the solution, the app.config file in the D3D10.example included the supported runtime, version=4 line. But it does NOT include a later line for the version=2 .net line, using the app.config as:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" />
  <supportedRuntime version="v2.0.50727" />
 </startup>
</configuration>

解决了问题,一旦将配置文件修改为显示的代码,所有示例都可以在 VS2012 中运行.

solved the problem, and all examples run in VS2012 once the config file is modified to the code shown.

我不知道这篇文章是否为时已晚,我本月刚开始使用 Windows 7 和 VS2012 进行图形项目,配置更改解决了我的问题.

I don't know if this post is to late for an answer, I'm just starting in windows 7 and VS2012 this month on a graphics project and the config change solved my problem.

这篇关于混合模式程序集是针对运行时的“2.0.50727"版本构建的,无法在 4.0 运行时中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆