new Bitmap() is throwing random, non-traceable exceptions
<p>I have a few spots in my code where I'm simply creating a new Bitmap object, like so:</p>

<pre class="lang-cs prettyprint-override"><code>bmpTile = new Bitmap(8, 8, PixelFormat.Format32bppArgb);
</code></pre>

<p>Easy, right? For some reason, I <em>randomly</em> get exceptions on lines like this. By random, I mean that I can't consistently reproduce the same exception on the same line after the same sequence of events. I can't even create a unit test for you guys to look at.</p>

<p>The most common exception I get is:</p>

<pre class="lang-none prettyprint-override"><code>ArgumentException: Parameter is not valid.
TargetSite: {Void .ctor(Int32, Int32, System.Drawing.Imaging.PixelFormat)}
</code></pre>

<p>The next most common one doesn't even give me a stack trace from inside my program:</p>

<pre class="lang-none prettyprint-override"><code>AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
StackTrace:
    at System.Drawing.SafeNativeMethods.Gdip.IntGdipDisposeImage(HandleRef image)
    at System.Drawing.SafeNativeMethods.Gdip.GdipDisposeImage(HandleRef image)
    at System.Drawing.Image.Dispose(Boolean disposing)
    at System.Drawing.Image.Finalize()
TargetSite: {Int32 IntGdipDisposeImage(System.Runtime.InteropServices.HandleRef)}
</code></pre>

<p>It looks like it's having trouble disposing the old Bitmap whenever I try to create a new one, but <em>why</em>? I am using LockBits and UnlockBits ubiquitously, but I'm always doing them in pairs: I never call LockBits without a subsequent UnlockBits.</p>

<p>So what could cause Dispose() to fail like this?</p>

<p>EDIT: I should mention that it's not happening on the second try. It happens on around the fifth or sixth try, meaning it has disposed of the first four or five Bitmaps without issue.</p>
