2012-11-24 96 views
3

我正在C#中使用3.5的.NET Framework製作應用程序,並具有解壓縮文件的功能;然而,當我運行它時,只要它到達解壓縮方法,它就會崩潰,出現Windows「停止工作」錯誤。它不會讀取方法內的任何行,只是在輸入時崩潰。Shell32.dll參考導致問題

Description: 
Stopped working 

Problem signature: 
Problem Event Name: CLR20r3 
Problem Signature 01: test.exe 
Problem Signature 02: 0.0.0.0 
Problem Signature 03: 50b03509 
Problem Signature 04: Test 
Problem Signature 05: 0.0.0.0 
Problem Signature 06: 50b03509 
Problem Signature 07: 1 
Problem Signature 08: 38 
Problem Signature 09: System.IO.FileNotFoundException 
OS Version: 6.1.7601.2.1.0.256.48 
Locale ID: 1033 

使用「停止工作菜單」中的調試功能後,出現此錯誤。

Could not load file or assembly 'Interop.Shell32, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. 

我使用此代碼在CodeDom編譯器內導入Shell32.dll。

Params.ReferencedAssemblies.Add("Interop.Shell32.dll"); 

下面是在崩潰的方法中解壓文件的代碼。

Shell32.ShellClass sc = new Shell32.ShellClass(); 
       Shell32.Folder SrcFlder = sc.NameSpace(source); 
       Shell32.Folder DestFlder = sc.NameSpace(dest); 
       Shell32.FolderItems items = SrcFlder.Items(); 
       DestFlder.CopyHere(items, 20); 

我不知道爲什麼會發生這種情況。它可以在原始應用程序中完美工作,但是當我使用CodeDom進行編譯(生成無錯誤)並運行它時,會發生這種情況。我沒有正確引用COM嗎?

+0

'無法加載文件或程序集 - 當您運行[ProcMon](http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx)並在發生問題時捕獲HDD活動跟蹤時,你能看到它正在尋找加載DLL的位置嗎?並與原始應用程序進行追蹤,並讓我們瞭解其差異。 –

+0

@JeremyThompson我有ProcMan,但我似乎無法弄清楚如何捕獲硬盤活動跟蹤。如果你不介意,你能解釋一下嗎?謝謝。 – Hexo

+0

@Hexo向下滾動頁面:http://forum.appointmentsbook.com/showthread.php?t=125 –

回答

0

無法加載文件或程序集「Interop.Shell32,版本= 1.0.0.0, 文化=中性公鑰=空」或它的一個依賴。 系統找不到指定的文件。

該引用已被加載到您的程序集中。但是你的應用程序找不到你的COM依賴。

您需要在主要可執行文件的根目錄上有'Interop.Shell32.dll'。

爲此,在Visual Studio上我們有一個選項,當點擊引用時,是'Copy Local' - 只設置爲true,並且依賴關係將被複制到下一個版本的應用程序文件夾中。

然後,您可以使用build文件夾中存在的庫文件運行您的應用程序。

+0

我已經完成了這一步,並將編譯後的文件放在包含「Interop.Shell32.dll」文件的調試文件夾中。但它仍然會出現相同的錯誤。 – Hexo