简体   繁体   English

在C#应用程序中使用C ++ / CLI时出现BadImageFormatException

[英]BadImageFormatException when using C++/CLI in a C# application

I am currently developing an application in VS 2008, in which I have a unmanaged C++ library (A) that wraps up two existing libraries (B + C) to simplify functionality. 我目前正在VS 2008中开发一个应用程序,其中有一个非托管C ++库(A),该库封装了两个现有库(B + C)以简化功能。 (A) has shown to work and I can successfully call and use it in a c++ test application. (A)已经证明可以工作,并且我可以在c ++测试应用程序中成功调用和使用它。

The main purpose of (A) is to be used by a C# application, in order to do this I have followed the following link: http://blogs.msdn.com/b/borisj/archive/2006/09/28/769708.aspx to create a CLI wrapper (D). (A)的主要目的是由C#应用程序使用,为此,我遵循以下链接: http : //blogs.msdn.com/b/borisj/archive/2006/09/28/ 769708.aspx以创建CLI包装器(D)。

All seems well, everything compiles and I have attempted to test this in a simple C# application. 一切似乎都很好,一切都可以编译,我试图在一个简单的C#应用​​程序中对此进行测试。 I added a reference to (D) and fired up the program only to receive the BadImageFormatException when trying to use the class. 我添加了对(D)的引用,并在尝试使用该类时仅触发了程序以接收BadImageFormatException。 From what I have read people suggest that there is a vesion mismatch in the DLLs somewhere, however I have built them all in Win32 to match each other. 根据我的阅读,人们建议DLL中存在版本不匹配,但是我在Win32中将它们全部构建为相互匹配。

In addition to this I have provided (D) and the C# application a copy of all the DLLs that are required but still seem to get a problem. 除此之外,我还提供了(D)和C#应用程序所有必需的DLL的副本,但似乎仍然出现问题。 I have noticed that a dll is not created for (D) when compiled which is my guess at why it is falling apart, however as I am new to this I don't know if it should or not. 我注意到编译时没有为(D)创建dll,这是我猜测它为什么会崩溃的原因,但是由于我是新手,所以我不知道它是否应该这样做。

Am I likely not including a DLL somewhere that I have overlooked that is causing this? 我是否可能在导致该问题的地方忽略了DLL?

TLDR: A wraps B + C, A is wrapped by D to be used in a C# application, but it hits and exception. TLDR:A包装B + C,A包装D以在C#应用程序中使用,但是命中和异常。 (I have put all DLL where they should go (to my knowledge) and ensured they all match). (据我所知,我已将所有DLL放在应放置的位置,并确保它们都匹配)。 Are there any gotchas that I may of missed? 我可能会错过任何陷阱吗?

Try to change your compilation mode to x86 or Any CPU Mode. 尝试将您的编译模式更改为x86或任何CPU模式。

Right Button click in your solution > Configuration Manager. 右键单击您的解决方案> Configuration Manager。

Or 要么

Build > Configuration Manager 生成>配置管理器

在此处输入图片说明

In the Configuration Manager change all projects to compile in x86 or ANy CPU, try both. 在配置管理器中,更改所有项目以在x86或ANy CPU中进行编译,请同时尝试两者。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM