2011-12-01 93 views
1

我有以下情况:我有一个Windows服务,使用Microsoft AddIn框架将许多外部.dll加载为AddIns。 AddIn .dlls分别位于位于包含service exe目录的“AddIns”目录中的各自目录中。每个AddIn .dll引用一个常见的程序集,这个程序集基本上是AddIns的一个API。我把它放在服务目录中。我遇到的问题是,API .dll文件必须在每一个外接程序目录也还是我的错误:无法加载.NET程序集

Exception has been thrown by the target of an invocation. - System.IO.FileNotFoundException: Could not load file or assembly 'OSAE.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

我也试过这个组件添加到这似乎把它放在C:\Windows\Microsoft.NET\assembly\GAC_MSIL\OSAE.API\v4.0_1.0.0.0__f47a6446f36f79f7 GAC中,但这似乎没有帮助。

我该如何告诉AddIns在程序集的特定目录中查找,或将它设置在全局可访问的位置?

回答

3

使用assembly binding log viewer(Fuslogvw.exe)查看运行时试图加载的内容以及它失败的位置。

The Assembly Binding Log Viewer displays details for assembly binds. This information helps you diagnose why the .NET Framework cannot locate an assembly at run time. These failures are usually the result of an assembly deployed to the wrong location, a native image that is no longer valid, or a mismatch in version numbers or cultures. The common language runtime's failure to locate an assembly typically shows up as a TypeLoadException in your application.

(重点煤矿)

0

为什么不在加载每个加载项DLL之前手动加载API.dll。如果加载项DLL加载到他们自己的应用程序域中,那么您也必须将API.dll加载到每个应用程序域中。如果他们加载到相同的应用程序域,那么你只需要加载一次API.dll。