Windows Form Application Stopped Working Due to Problem Event Name CLR20r3

2012-01-19


There was a windows forms application based on .NET 4.0 and Visual Studio 2010, it was working well on a PC which we developed it on, but after we moved its debug folder that includes generated executable files, it crashed (We used Windows 7):

CLR20r3Error0

We expanded the "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:<span class="rem">//go.microsoft.com/fwlink/?linkid=104288&amp;clcid=0x0409</span>

If the online privacy statement <span class="kwrd">is</span> not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt

Due to the above information, seems our application lost some files which should be included in the output folder. but what are the files?

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:

CLR20r3Error1

So now we know the missed the file is related to "Microsoft.VisualBasic.PowerPacks.Vs", it is a library file. The file is 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.