title: Unhandled System.NullReferenceException in Form.Dispose() WinForms .NET app?
body: <p>I have a WinForms .NET app that crashed on a user's computer.  The Windows Error Report said it was a System.NullReferenceException.  </p>
  
  <p>After using the instructions on this page (<a href="http://blogs.msdn.com/b/oanapl/archive/2009/01/30/windows-error-reporting-wer-and-clr-integration.aspx" rel="nofollow">http://blogs.msdn.com/b/oanapl/archive/2009/01/30/windows-error-reporting-wer-and-clr-integration.aspx</a>) I was able to determine the problem to have occurred in Form.Dispose(boolean).  </p>
  
  <p>However, since the .Dispose() method is part of .NET and not something that I wrote, is there any way that I can prevent it from happening again?  I am currently not able to reproduce the problem because I don't know exactly what steps to take to reproduce it.</p>
  
  <p>If anyone has any insight on how I might figure out more detail to this issue, I would appreciate it.</p>
  
  <p>EDIT:
  To be clear, I am not calling .Dispose directly but rather am just calling .Close() in my code.</p>
  
  <p>Below is the Windows Error Report information, followed by the output of windbg that I obtained by following the instructions in the link posted above.  </p>
  
  <p>If I'm reading this correctly, the issue occurred in .Dispose(), but perhaps I've misread the output?</p>
  
  <pre><code>Problem Event Name: CLR20r3
  Problem Signature 01: MyApp.exe
  Problem Signature 02: 0.0.0.0
  Problem Signature 03: 52fd3d6b
  Problem Signature 04: MyApp
  Problem Signature 05: 0.0.0.0
  Problem Signature 06: 52fd3d6b
  Problem Signature 07: 35b
  Problem Signature 08: b5
  Problem Signature 09: System.NullReferenceException
  
  
  0:013&gt; !token2ee MyApp 06000035
  Module:      000007fe98762f98
  Assembly:    MyApp.exe
  Token:       0000000006000035
  MethodDesc:  000007fe98a75220
  Name:        MyApp.Form_ColumnEditing.Dispose(Boolean)
  JITTED Code Address: 000007fe98a159e0
  
  0:013&gt; !dumpil 000007fe98a75220
  ilAddr = 00000000012c3a70
  IL_0000: nop 
  IL_0001: ldarg.1 
  IL_0002: brfalse.s IL_000f
  IL_0004: ldarg.0 
  IL_0005: ldfld MyApp.Form_ColumnEditing::components
  IL_000a: ldnull 
  IL_000b: ceq 
  IL_000d: br.s IL_0010
  IL_000f: ldc.i4.1 
  IL_0010: stloc.0 
  IL_0011: ldloc.0 
  IL_0012: brtrue.s IL_0022
  IL_0014: nop 
  IL_0015: ldarg.0 
  IL_0016: ldfld MyApp.Form_ColumnEditing::components
  IL_001b: callvirt System.IDisposable::Dispose 
  IL_0020: nop 
  IL_0021: nop 
  IL_0022: ldarg.0 
  IL_0023: ldarg.1 
  IL_0024: call System.Windows.Forms.Form::Dispose 
  IL_0029: nop 
  IL_002a: ret 
  </code></pre>