【问题】
之前折腾C#项目中,将dll集成到exe中,后来使用的办法是,不使用资源文件,不适用动态reflection代码,直接拷贝dll到项目文件夹内,然后添加引用该dll文件。
结果生成的exe运行出错:
错误内容:
Unhandled exception has occurred in your application.
If you click Continue, the application will ignore this error and attempt to continue.
If you click Quit, the application will close immediately.
Could not load file or assembly ‘Interop.SHDocVw, Version=1.1.0.0
Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.
错误截图:
对应log:
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.IO.FileNotFoundException: Could not load file or assembly 'Interop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. File name: 'Interop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null' at downloadSongtasteMusic.songtaste.getMultiPlayingPage() at downloadSongtasteMusic.songtaste.getCurPlayingSongId(String& curSongId) at downloadSongtasteMusic.frmDownloadSongtasteMusic.downloadPlayingStMusic() at downloadSongtasteMusic.frmDownloadSongtasteMusic.doDownload() at downloadSongtasteMusic.frmDownloadSongtasteMusic.btnDownload_Click(Object sender, EventArgs e) at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 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]. ************** Loaded Assemblies ************** mscorlib Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.5456 (Win7SP1GDR.050727-5400) CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll ---------------------------------------- downloadSongtasteMusic Assembly Version: 1.0.0.0 Win32 Version: 1.4.0.0 CodeBase: file:///D:/to_del/st_test/downloadSongtasteMusic.exe ---------------------------------------- System.Windows.Forms Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.5460 (Win7SP1GDR.050727-5400) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll ---------------------------------------- System Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.5456 (Win7SP1GDR.050727-5400) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll ---------------------------------------- System.Drawing Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.5462 (Win7SP1GDR.050727-5400) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll ---------------------------------------- System.Configuration Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll ---------------------------------------- System.Xml Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400) CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll ---------------------------------------- System.Web Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.5456 (Win7SP1GDR.050727-5400) CodeBase: file:///C:/Windows/assembly/GAC_32/System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll ---------------------------------------- Microsoft.mshtml Assembly Version: 7.0.3300.0 Win32 Version: 7.0.3300.0 CodeBase: file:///C:/Windows/assembly/GAC/Microsoft.mshtml/7.0.3300.0__b03f5f7f11d50a3a/Microsoft.mshtml.dll ---------------------------------------- ************** JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled. For example: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.
【解决过程】
1.很明显,错误是找不到对应的,程序所依赖的dll库文件:Interop.SHDocVw.dll,所以,看来此办法,还是行不通,会导致程序运行时出错找不到对应的dll。
【总结】
所以,看来还是需要换用别的之前的那些办法,比如把dll当做资源加载进来,然后设置为内嵌资源。
详细折腾过程,参见:
注:如果你是作为程序的用户,去运行别的程序出现此错误,那原因是该程序开发者制作程序时所用的一些dll等库文件,在你当前电脑(系统)中找不到。
而解决办法,对于程序的用户来说,那貌似基本没有。
因为你作为普通用户,只是发现了此程序的一个bug而已。只能把此错误报告为程序开发者,让其去解决此问题。
转载请注明:在路上 » 【已解决】C#编译出来的程序运行出错:Unhandled exception has occurred in your application。System.IO.FileNotFoundException: Could not load file or assembly xxx or one of its dependencies. The system cannot find the file specified.