title: Access Violation Exception in Forms.ShowDialog
body: <p>I get an <code>AccessViolationException</code> every time I call the <code>ShowDialog()</code> Method of a Form I created. The problem occurs only when the <code>CheckkedListBox</code> <code>moduleOperationsBox</code> contains Elements. There are other elements of type <code>ListBox</code> that work just fine.</p>
  
  <p>Here the corresponding code parts:</p>
  
  <p>The ShowDialog() Call:</p>
  
  <pre><code>public new System.Windows.Forms.DialogResult ShowDialog()
  {
      foreach(KeyValuePair&lt;string, string&gt; foo in obsoleteOperations)
      {
          moduleOperationsBox.Items.Add(foo);
      }                   
      return base.ShowDialog();
  }
  </code></pre>
  
  <p>Related parts of the Constructor:</p>
  
  <pre><code>public ModuleSyncDialog(EA.Repository rep)
  {
      InitializeComponent();
      obsoleteOperations = new List&lt;KeyValuePair&lt;string, string&gt;&gt;();
  
      this.moduleOperationsBox.DisplayMember = "Key";
      this.moduleOperationsBox.ValueMember = "Value";                   
  }
  </code></pre>
  
  <p>Method to fill the List:</p>
  
  <pre><code>public void addModuleOperation(string name, string guid)
  {
      obsoleteOperations.Add(new KeyValuePair&lt;string, string&gt;(name,guid));
  }
  </code></pre>
  
  <p>and the StackTrace:</p>
  
  <pre><code>   bei System.Drawing.SafeNativeMethods.Gdip.GdipDrawRectangleI(HandleRef graphics, HandleRef pen, Int32 x, Int32 y, Int32 width, Int32 height)
     bei System.Drawing.Graphics.DrawRectangle(Pen pen, Int32 x, Int32 y, Int32 width, Int32 height)
     bei System.Windows.Forms.ControlPaint.DrawFlatCheckBox(Graphics graphics, Rectangle rectangle, Color foreground, Brush background, ButtonState state)
     bei System.Windows.Forms.ControlPaint.DrawFlatCheckBox(Graphics graphics, Rectangle rectangle, ButtonState state)
     bei System.Windows.Forms.ControlPaint.DrawCheckBox(Graphics graphics, Int32 x, Int32 y, Int32 width, Int32 height, ButtonState state)
     bei System.Windows.Forms.ControlPaint.DrawCheckBox(Graphics graphics, Rectangle rectangle, ButtonState state)
     bei System.Windows.Forms.CheckedListBox.OnDrawItem(DrawItemEventArgs e)
     bei System.Windows.Forms.ListBox.WmReflectDrawItem(Message&amp; m)
     bei System.Windows.Forms.ListBox.WndProc(Message&amp; m)
     bei System.Windows.Forms.CheckedListBox.WndProc(Message&amp; m)
     bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
     bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
     bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     bei System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
     bei System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
     bei System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message&amp; m)
     bei System.Windows.Forms.Control.WmOwnerDraw(Message&amp; m)
     bei System.Windows.Forms.Control.WmDrawItem(Message&amp; m)
     bei System.Windows.Forms.Control.WndProc(Message&amp; m)
     bei System.Windows.Forms.ScrollableControl.WndProc(Message&amp; m)
     bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
     bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
     bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     bei System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
     bei System.Windows.Forms.NativeWindow.DefWndProc(Message&amp; m)
     bei System.Windows.Forms.Control.DefWndProc(Message&amp; m)
     bei System.Windows.Forms.Control.WndProc(Message&amp; m)
     bei System.Windows.Forms.ListBox.WndProc(Message&amp; m)
     bei System.Windows.Forms.CheckedListBox.WndProc(Message&amp; m)
     bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
     bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
     bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
     bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
     bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
     bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
     bei System.Windows.Forms.Application.RunDialog(Form form)
     bei System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
     bei System.Windows.Forms.Form.ShowDialog()
     bei ModelAssistant.ModuleSyncDialog.ShowDialog() in C:\Dokumente und Einstellungen\ostwal99\Eigene Dateien\EA_EXTENSIONS\EA_ADDIN\src\AEPAddIn\ModelAssistant\ModuleSyncDialog.designer.cs:Zeile 524.
     bei ModelAssistant.ModelAssistant.synchronizeInterface(Repository repository, Element eaInterface) in C:\Dokumente und Einstellungen\ostwal99\Eigene Dateien\EA_EXTENSIONS\EA_ADDIN\src\AEPAddIn\ModelAssistant\ModelAssistant.cs:Zeile 436.
     bei ModelAssistant.ModelAssistant.EA_OnNotifyContextItemModified(Repository repository, String guid, ObjectType ot) in C:\Dokumente und Einstellungen\ostwal99\Eigene Dateien\EA_EXTENSIONS\EA_ADDIN\src\AEPAddIn\ModelAssistant\ModelAssistant.cs:Zeile 188.
     bei AEPAddInHost.AEPAddInHost.EA_OnNotifyContextItemModified(Repository repository, String guid, ObjectType ot) in C:\Dokumente und Einstellungen\ostwal99\Eigene Dateien\EA_EXTENSIONS\EA_ADDIN\src\AEPAddIn\AEPAddInHost\AEPAddInHost.cs:Zeile 151.
  </code></pre>
  
  <p>It was compiled with VS2010 under WindowsXP SP3, .Net Framework 4.</p>
  
  <p>Would be really nice if you post any ideas to solve the problem or need additional Information.</p>
  
  <p>Thanks.</p>