我有一个我猜是在 x64 中构建的程序集,我想在任何 CPU配置的项目中引用它。但是当我使用任何 CPU 平台将该 .net 程序集引用到项目时,我收到以下警告
warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Users\QvAdmin\Documents\Visual Studio 2013\Projects\QvAccessPointT2\x64\Debug\CppT1.exe", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
因此,我尝试使用此处描述的 c++ 混合模式程序集。我创建了一个 CLR 控制台应用程序(C++)。
但是我再次遇到了我长期与之抗争的同样的例外。在显示的解决方案中,CSharpT1 是引用 CppT1(一个 CLR Cpp 控制台应用程序项目)的启动项目。读完这篇文章后我所期望的是,我可以毫无问题地引用 CppT1,因为它是一个 Cpp 项目并且配置设置为 x64。但问题依然存在。我的想法是抛出 Cpp 项目,我将能够加载 x64 程序集。这是另一个参考。
Message: An unhandled exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'CppT1, Version=1.0.5578.39432, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.