There was a windows form application based on .NET 4.0 and Visual Studio 2010, it was working well on a PC which we developed it. when we move its debug folder which including generated executable files, it crashed (We use Windows 7): We expanded “Show problem details” button and saw the following information: Description: Stopped working Problem signature: Problem Event Name: CLR20r3 Problem Signature 01: cnserver.exe Problem Signature 02: 1.0.0.0 Problem Signature 03: 4f16e189 Problem Signature 04: CnServer Problem Signature 05: 1.0.0.0 Problem Signature 06: 4f16e189 Problem Signature 07: 225 Problem Signature 08: 6 Problem Signature 09: System.IO.FileNotFoundException OS Version: 6.1.7600.2.0.0.256.48 Locale ID: 1033 Read our privacy statement online: http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409 If the online privacy statement is not available, please read our privacy statement offline: C:\Windows\system32\en-US\erofflps.txt Due to above information, sees our application missed some files which should be included in output folder. but what the files are ? Obviously we have some unhandled exceptions in our program due to the error message and the crash, we can not see apparent reason, so we should add the missed exceptions handler. For example: AppDomain.CurrentDomain.UnhandledExceptio Then we add the handlercode into the application startup process, In our case, we add the code in Program.cs file, see the following code, you will see what code you should add into your Program.cs: static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.Run(new Form1()); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { MessageBox.Show(((Exception)e.ExceptionObject).Message, "Unhandled UI Exception"); } static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { MessageBox.Show(e.Exception.Message, "Unhandled Thread Exception"); } } After we added above code, we ran our application again, and got a popup window like the following: So then we know the missed the file is about “Microsoft.VisualBasic.PowerPacks.Vs”, it is a library file. it missed on the new PC, so we just “include” the dll file to output folder in Visual Studio 2010, then our application can work on other PCs. |
|
来自: goodwangLib > 《C#》