简体   繁体   English

COM应用程序引用的dll故障排除

[英]COM application referenced dlls troubleshooting

I have a WPF application, which I build as a dll COM component and install using installshieldLE, however I have some issues with some dependent dlls, when running my COM client. 我有一个WPF应用程序,我将其作为DLL COM组件构建并使用installshieldLE安装,但是在运行COM客户端时,某些依赖的dll存在一些问题。

My WPF dll references two other C# dlls (A & B) which reside within the same VS2012 solution. 我的WPF dll引用了驻留在同一VS2012解决方案中的另外两个C#dll(A和B)。

My WPF dll has the register for COM interop option checked and provides a COM interface for running the WPF GUI application. 我的WPF dll已选中“注册COM互操作注册”选项,并提供了用于运行WPF GUI应用程序的COM接口。

I have a C COM client program, which tests the WPF application. 我有一个C COM客户端程序,用于测试WPF应用程序。 The problem I am having is that I need to include some of dll_A's referenced dlls, (which is a third party graphics package) in the folder of the client program for the application to run successfully. 我遇到的问题是,我需要在客户端程序的文件夹中包含一些dll_A引用的dll(这是第三方图形包),以使应用程序成功运行。 I don't have to include dll_A or dll_B in the local client directory. 我不必在本地客户端目录中包含dll_A或dll_B。

Also, there are other (C) dlls referenced by the COM server dll and included in the installation that do not need to be present in the client directory, so this is difficult to understand. 另外,COM服务器dll引用并包含在安装中的其他(C)dll不需要出现在客户端目录中,因此这很难理解。

I assume that this is not a WPF question but simply a question about com server installation in relation to other referenced assemblies. 我假设这不是WPF问题,而仅仅是与其他引用程序集有关的com服务器安装问题。

I have output some debug messages in the primary dlls that confirm that the dlls A&B, along with the main COM dll are being run from the installation location. 我已经在主要dll中输出了一些调试消息,这些消息确认dll A&B以及主要的COM dll正在从安装位置运行。 But I get exceptions further down the line when the third party dlls are missing from the local client folder. 但是,当本地客户端文件夹中缺少第三方dll时,我会进一步抛出异常。

Can someone help me troubleshoot this problem please. 有人可以帮我解决这个问题。 I can run the client program successfully from the installation location and am therefore certain that all required assemblies and dlls are present. 我可以从安装位置成功运行客户端程序,因此可以确定所有必需的程序集和dll都存在。

Thanks. 谢谢。

It sounds like you're encountering issues related to the DLL load path. 听起来您遇到了与DLL加载路径有关的问题。 A client application can load your COM DLL, but your COM DLL can't load its own dependencies (or dependencies of dependencies, etc) even through the dependencies exist in the same folder as the COM DLL. 客户端应用程序可以加载您的COM DLL,但是即使通过与COM DLL相同的文件夹中存在的依赖关系,您的COM DLL也无法加载其自己的依赖关系(或依赖关系的依赖关系等)。 Is this correct? 这个对吗?

If so, I believe this problem can be solved with a call to the AddDllDirectory function -- just have your COM DLL call this before loading any of its dependencies and call RemoveDllDirectory when it's done. 如果是这样,我相信可以通过调用AddDllDirectory函数来解决此问题-只需在加载任何依赖项之前让您的COM DLL调用此RemoveDllDirectory ,然后在完成后调用RemoveDllDirectory For more information, see the Remarks section of the documentation for LoadLibrary . 有关更多信息,请参见LoadLibrary文档的“备注”部分。

The problem was caused by one of the referenced dlls being compiled using .Net 4.0, whereas the others were compiled using .Net 4.0 client. 该问题是由使用.Net 4.0编译的引用dll之一引起的,而其他问题是使用.Net 4.0客户端编译的。 Recompiling with .Net 4.0 Client resolved the problem. 使用.Net 4.0客户端重新编译解决了该问题。

The problem seemed to occur when executing the application as a registered com component, with the client being executed from a different location. 当将应用程序作为已注册的com组件执行,并且客户端从其他位置执行时,似乎会出现问题。 If the offending dlls were copied to the client directory, everything runs fine. 如果将有问题的dll复制到客户端目录,则一切运行正常。

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

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