2014-04-15 28 views
-2

我正在使用.NET dll文件進行圖像操作,並使用解決方案資源管理器中的「添加引用」將其添加到我的C#應用​​程序中,並使用它的類。有許多應用程序使用的DLL,所以我不想要的dll文件放在像一個專用的文件夾:添加對Windows System32文件夾中的.NET庫的引用

  • C:\Program Files\<Application Name>\
  • C:\Program Files (x86)\<Application Name>\
  • C:\ProgramData\<Application Name>\
  • C:\Users\<Username>\AppData\

並希望將dll文件放置在一個通用文件夾中,如C:\Windows\C:\Windows\System32文件夾或任何文件夾Windows中所有應用程序都可以訪問的其他文件夾。我的應用程序的C#代碼無法找到DLL並給出錯誤:

Unable to load DLL: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

如何指示我的代碼在system32目錄或任何其他公用目錄中查找dll?

可以使用共享的dll和庫的其他常用文件夾?

+0

不要那樣做。改用'Program Files \ Common Files \ <你的子目錄>'。 –

+2

閱讀[DLL Hell](http://en.wikipedia.org/wiki/Dll_hell),瞭解爲什麼你要求的東西是一個*糟糕的*想法。 –

+0

@JoeWhite好的。問題是大多數時候dll已經放在System32目錄中,如果在安裝過程中已經找到dll,代碼將使用該dll。但我不知道如何訪問C#代碼中的Windows/system32 dll。 –

回答

1

這是全局程序集緩存的設計目的。如MS文檔here中所列。

Each computer where the common language run-time is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.

但也有陷阱,以使用它,知道MS自己的建議:

You should share assemblies by installing them into the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required.

+0

謝謝。你能分享一個關於如何在C#/ Visual Studio中使用GAC的示例代碼的鏈接或教程嗎? –

相關問題