[英]c# app can't find dll in its working directory
我剛剛從 C++ 切換到 C#,我對引用 DLL 有點困惑。
我有一個第三方 DLL 和一個使用其某些方法的簡單測試應用程序。 當我編譯項目時,一切順利,但是當我在另一台計算機上運行編譯的應用程序時,我收到一個錯誤,指出 DLL 丟失,即使 DLL 位於應用程序的工作目錄中。 更奇怪的是,我可以訪問另一個依賴於該 DLL 舊版本的應用程序的源代碼,並且該應用程序運行良好。
我已經瀏覽了代碼和所有解決方案設置,但沒有發現任何真正不同的東西。
您能告訴我如何從工作目錄 (Visual Studio 2010) 中引用.dll
嗎?
以下是例外:
System.IO.FileNotFoundException was unhandled
Message=Could not load file or assembly 'TIS.Imaging.ICImagingControl32, Version=3.2.4.1146, Culture=neutral, PublicKeyToken=257805929e8b7928' or one of its dependencies. The system cannot find the file specified.
Source=ICtestapp
FileName=TIS.Imaging.ICImagingControl32, Version=3.2.4.1146, Culture=neutral, PublicKeyToken=257805929e8b7928
FusionLog=WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
StackTrace:
at ICtestapp.Form1.InitializeComponent()
at ICtestapp.Form1..ctor()
at ICtestapp.Program.Main()
InnerException:
這是 .net 團隊的 Suzanne Cook 關於調試 .net 加載程序問題的一篇很好的博客文章。
http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx
這是有關它如何加載的詳細信息:
http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.71).aspx
您必須在項目引用中添加 dll 作為引用,一旦在引用中添加了庫,當您編譯程序時,除非在引用屬性中另有指定,否則 dll 將自動復制到編譯輸出文件夾中...
然后,如果您將在編譯輸出文件夾中找到的所有項目復制到另一台 PC 的新位置,則應該不會出現任何問題。
還要檢查安裝在另一台機器上的 .NET 框架至少與項目目標的級別相同..
當您將調試可執行文件復制到另一台機器時,也會發生這種情況。 嘗試在發布中編譯並移動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.