2011-12-01 103 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。