在.net 4.0 wpf应用程序中使用.net 2.0 dll [英] use .Net 2.0 dll in .net 4.0 wpf application

查看:35
本文介绍了在.net 4.0 wpf应用程序中使用.net 2.0 dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在针对.Net 4框架的WPF应用程序中添加对.Net 2.0 DLL的引用.

I am trying to add a reference to a .Net 2.0 DLL in a WPF application that is targeted to the .Net 4 Framework.

我在app.config文件中添加了< startup useLegacyV2RuntimeActivationPolicy ="true"> .WPF应用程序构建良好,但是在尝试访问.Net 2.0 DLL时在运行时遇到BadImageFormatException.

I added <startup useLegacyV2RuntimeActivationPolicy="true"> to the app.config file. The WPF app builds fine, but gets a BadImageFormatException at Runtime when trying to access the .Net 2.0 DLL.

试图加载格式错误的程序"

"An attempt was made to load a program with an incorrect format"

这适用于新的测试WPF项目,但不适用于我的应用程序.我的应用程序使用实体框架和MEF.这些技术会导致问题吗?

This works with a new test WPF project, but does not work on my app. My app uses Entity Framework and MEF. Could these technologies be causing the issue?

有什么想法吗?

已解决

根据下面的Alois的评论,我的主应用程序定位于任何CPU",而DLL定位于32位.

According to the comment by Alois below, I had my main app targeted to 'Any CPU' and the DLL was targeted to 32-bit.

<启动useLegacyV2RuntimeActivationPolicy ="true">

推荐答案

当您必须使用useLegacyV2RuntimeActivationPolicy属性时,您将使用以C ++/CLI编写且目标版本为2.0.50727的混合模式程序集.CLR.这样的程序集包含托管代码和本机代码.在您的情况下,该机器代码是32位的,因此您不能在64位的进程中运行它.这就是异常的含义.需要在EXE项目中将Platform目标设置为x86.

When you have to use the useLegacyV2RuntimeActivationPolicy attribute then you are working with a mixed-mode assembly that was written in C++/CLI and targeting version 2.0.50727 of the CLR. Such an assembly contains both managed code and native machine code. That machine code is 32-bit in your case, you can't run it in a 64-bit process. Which is what the exception means. Setting the Platform target to x86 in your EXE project is required.

这篇关于在.net 4.0 wpf应用程序中使用.net 2.0 dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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