简体   繁体   English

无法在Vista x64的C#应用​​程序中加载C ++ DLL

[英]Unable to load C++ DLL in C# application in Vista x64

I have a DLL written in C++ that needs to be used by an application in C#. 我有一个用C ++编写的DLL,需要由C#中的应用程序使用。 It works great under Vista x86, but under x64 it fails to load. 它在Vista x86上运行良好,但在x64下无法加载。 So I build an x64 version of the DLL and I detect whether the OS is x86 or x64 and use the appropriate interop call to the appropriate DLL. 因此,我构建了DLL的x64版本,并检测到操作系统是x86还是x64,并使用了对适当DLL的适当互操作调用。 This works fine under Vista x86, but under Vista x64 I get a "side-by-side" error when it tries to load the DLL. 在Vista x86下可以正常工作,但是在Vista x64下,尝试加载DLL时出现“并排”错误。 Why exactly is it failing to load it, and what can be done to correct this? 为什么它无法正确加载,该如何解决? (Please let me know if you need more information, I'm not sure what information is relevant in trouble-shooting this issue.) (如果您需要更多信息,请告诉我,我不确定在解决此问题时会涉及到哪些信息。)

One first idea: Could you try setting the "Platform Target" setting in the C# part of the project to "x86", to see if it will run in 32-bit compatibility mode on the Vista 64 machine? 第一个想法:能否将项目C#部分中的“平台目标”设置设置为“ x86”,以查看它是否将在Vista 64计算机上以32位兼容模式运行?

More information about the SxS error would be useful - it might be related to some specific (32-bit?) versions of the runtime libraries that are not installed? 有关SxS错误的更多信息将很有用-它可能与某些未安装的运行时库的特定(32位?)版本有关?

some further information to the answer of MadKeithV: 有关MadKeithV答案的更多信息:

In Windows x64 a process may be started as 32bit or 64bit process. 在Windows x64中,进程可能以32位或64位进程启动。 A 64bit process can only load 64bit dlls and a 32bit process only 32bit dlls. 64位进程只能加载64位dll,而32位进程只能加载32位dll。

If your platform target (eg specified in the project properties) of your .Net application is set to "Any CPU", the intermediate code will be compiled to 32bit or 64bit code depending on the target platform, ie on a x64 system 64bit code will be generated. 如果您的.Net应用程序的平台目标(例如,在项目属性中指定)设置为“ Any CPU”,则根据目标平台,中间代码将编译为32位或64位代码,即在x64系统上,64位代码将被生成。

Therefore the code can no longer load a 32bit dll. 因此,该代码无法再加载32位dll。

If your code loads unmanaged assemblies you should always specify the target platform explicitly. 如果您的代码加载了非托管程序集,则应始终明确指定目标平台。

The redist for VC90 for x64 will need to be installed on the client machine. VC90 x64版的redist将需要安装在客户端计算机上。 As far as the manifest goes, I think you can alter it to remove the processorArchitecture tag. 就清单而言,我认为您可以对其进行更改以删除processorArchitecture标签。 Either that or have it say "any". 要么让它说“ any”。

If nothing else works.. you can give Process Monitor a try. 如果没有其他效果,则可以尝试使用Process Monitor It shows you which file (dependency) was not found.. this may give you a lead to proceed. 它向您显示未找到哪个文件(依赖项)。这可能会导致您继续操作。

The side by side error is more then likely caused by you c++ dll manifest file settings either they are not getting embedded or you have chosen to not embed the manifest and is using the 32bit versions manifest. 并排错误的可能性更大,可能是由于您未嵌入c ++ dll清单文件设置,或者您选择不嵌入清单而使用32位版本的清单。

The simple solution is to mark your c# application as for the x86 cup and run with the 32bit dll. 简单的解决方案是将c#应用程序标记为x86 cup,并以32位dll运行。

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

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