title: RegisterClass error in Unity Editor when using Mono.WinForms
body: <p>I'm using <code>Mono.WinForms</code> to create external windows in Unity and it works great except that I get this error message each time I play the scene (but never the first time when Unity is freshly started): </p>
  
  <blockquote>
    <p>Could not register the window class, win32 error 0.</p>
  </blockquote>
  
  <p>I figured that it was because that the form classes are not unregistered when I stop the scene. They do get unregistered when I restart Unity and I don't have the problem when I make a build, which makes sense.</p>
  
  <p>I get this popup error twice and it's caused by:</p>
  
  <ol>
  <li><code>myForm = new Form1();</code></li>
  <li><code>myForm.Show();</code></li>
  </ol>
  
  <p>I went through the code of the <code>XplatUIWin32.cs</code> file and found the <code>RegisterWindowClass</code> method. When Mono registers a class it does this:</p>
  
  <pre><code>class_name = string
           .Format("Mono.WinForms.{0}.{1}", 
             System.Threading.Thread.GetDomainID ().ToString (), classStyle);
  </code></pre>
  
  <p>So I managed to get rid of the second error by doing this:</p>
  
  <pre><code>UnregisterClass("Mono.WinForms.1.0", IntPtr.Zero);
  </code></pre>
  
  <p>So my question is why does it only work for the 2nd popup error and how do I get rid of the 1st one? I tried to force the garbage collection but it didn't help. I tried to find another registered class name but no luck here neither.</p>
  
  <p>For info I use the mono version of System.Windows.Forms.dll as a reference, compile my code in Visual Studio and import the produced DLL in Unity. It works great apart from those popup errors.</p>