title: C# .NET 2 exception: External component has thrown an exception
body: <p>I have developed in c# 2 applications. One ASP .NET web service and a WinForms client that uses the web service. The client is distributed to many customers. For one of these customers, suddenly the application started throwing the following exception:</p>
  
  <pre><code>External component has thrown an exception.
  at System.Diagnostics.SharedPerformanceCounter.GetCounter(String counterName, String instanceName, Boolean enableReuse, PerformanceCounterInstanceLifetime lifetime)
  at System.Diagnostics.SharedPerformanceCounter..ctor(String catName, String counterName, String instanceName, PerformanceCounterInstanceLifetime lifetime)
  at System.Diagnostics.PerformanceCounter.Initialize()
  at System.Diagnostics.PerformanceCounter.set_RawValue(Int64 value)
  at System.Net.NetworkingPerfCounters.Initialize()
  at System.Net.Configuration.SettingsSectionInternal..ctor(SettingsSection section)
  at System.Net.Configuration.SettingsSectionInternal.get_Section()
  at System.Net.ServicePointManager.set_Expect100Continue(Boolean value)
  at #Neh.#hgh.#P0f(String[] args)
  </code></pre>
  
  <p>The obfuscated (using SmartAssembly 5) function at the end of the exception, is client's main function which is as follows</p>
  
  <pre><code>public static void Main(string[] args) {
      try {
          AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
          Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
  
          System.Net.ServicePointManager.Expect100Continue = false;
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
  
          Globals.Settings.NoWaitPrintJobs = true;
          Application.Run(new frmMain());
      }
      catch(Exception ex) {
          HandleUnhandledException(ex);
      }
  }
  </code></pre>
  
  <p>From the exception I understand that it is breaking at line</p>
  
  <pre><code>System.Net.ServicePointManager.Expect100Continue = false;
  </code></pre>
  
  <p>The application doesn't reference any interop components, just other managed dlls. It's also using a native function in shell32.dll</p>
  
  <pre><code>[DllImport("shell32.dll")]
  static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, bool fCreate);
  </code></pre>
  
  <p>that is being called on main form load event from a static object.</p>
  
  <pre><code>Globals.Settings.InitLocalFiles();
  </code></pre>
  
  <p>I don't know the customer's computer specifications yet. I think he has Windows XP.
  Any thoughts please?</p>