title: System.Runtime.InteropServices.COMException in Windows Application
body: <p>I have developed a Windows application in Visual Studio 2012 with target framework as .NET 4. I deploy it in a Windows XP SP2 machine. It used to work fine, but now Windows XP was re-installed and the application is not working. I have installed the .NET 4 framework in XP but it shows the following error (from Event Viewer):</p>
  
  <pre><code>Application: SGate.exe
  Framework Version: v4.0.30319
  Description: The process was terminated due to an unhandled exception.
  Exception Info: System.Runtime.InteropServices.COMException
  Stack:
     at System.RuntimeTypeHandle.CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)
     at System.RuntimeType.CreateInstanceSlow(Boolean, Boolean, Boolean)
     at System.RuntimeType.CreateInstanceDefaultCtor(Boolean, Boolean, Boolean, Boolean)
     at System.Activator.CreateInstance(System.Type, Boolean)
     at SGate.Gate..ctor()
     at SGate.Program.Main()
  </code></pre>
  
  <p>I googled for solutions, I figured the exception means "The exception that is thrown when an unrecognized HRESULT is returned from a COM method call." But that doesn't help. Does anyone  know what causes this error?</p>
  
  <p>Program.Main():</p>
  
  <pre><code>static class Program
      {
          /// &lt;summary&gt;
          /// The main entry point for the application.
          /// &lt;/summary&gt;
          [STAThread]
          static void Main()
          {
              Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new Gate());
          }
      }
  </code></pre>
  
  <p>Gate ctr() and related function:</p>
  
  <pre><code>public Gate()
          {
              InitializeComponent();
              ClearForm();           
          }
  
  private void ClearForm()
          {
              try
              {
                  leaveApply = new EmployeeLeaveApplyBO();
                  CurrentPageIndex = 1;
                  dataGridView1.DataSource = null;
                  lblFromDate.Text = "";
                  lblLeaveReason.Text = "";
                  lblLeavType.Text = "";
                  lblName.Text = "";
                  lblEmpCode.Text = "";
                  lblThumbID.Text = "";
                  lblToDate.Text = "";
                  lblStatus.Text = "STATUS";
                  lblStatus.ForeColor = Color.Black;
                  groupBox3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
                  groupBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
              }
              catch (Exception e)
              {
                  LogUtil.LogError(e.ToString());
              }
          }
  </code></pre>