title: Visual Studio 2012 - vshost32-clr2.exe has stopped working
body: <p>I'm creating a WinForm Application in C# using Visual Studio 2012 and I'm getting an error when I debug it :</p>
  
  <pre><code>vshost32-clr2.exe has stopped working
  </code></pre>
  
  <p>I already searched but most results are for Visual Studio 2010 and lower and I get similar solutions which I think is not applicable to Visual Studio 2012 :</p>
  
  <pre><code>Properties -&gt; Debug -&gt; Enable unmanaged code debugging
  </code></pre>
  
  <p><em>Source : <a href="https://stackoverflow.com/questions/735621/vshost32-exe-crash-when-calling-unmanaged-dll">vshost32.exe crash when calling unmanaged DLL</a></em></p>
  
  <p><strong>Additional Details :</strong></p>
  
  <ul>
  <li><p>My project doesn't use any DLL.</p></li>
  <li><p>As far as I progress in my project, it only occurs when the width is <strong>17</strong>.</p></li>
  </ul>
  
  <p>I use the following code :</p>
  
  <pre><code>        Bitmap tmp_bitmap = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
  
          Rectangle rect = new Rectangle(0, 0, 16, tmp_bitmap.Height);
          System.Drawing.Imaging.BitmapData bmpData =
              tmp_bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
              tmp_bitmap.PixelFormat);
  
          unsafe
          {
              // Get address of first pixel on bitmap.
              byte* ptr = (byte*)bmpData.Scan0;
  
              int bytes = Width * Height * 3; //124830 [Total Length from 190x219 24 Bit Bitmap]
              int b;  // Individual Byte
  
              for (int i = 0; i &lt; bytes; i++)
              {
                  _ms.Position = EndOffset - i;  // Change the fs' Position
                  b = _ms.ReadByte();              // Reads one byte from its position
  
                  *ptr = Convert.ToByte(b);
                  ptr++;
  
                  // fix width is odd bug.
                  if (Width % 4 != 0)
                      if ((i + 1) % (Width * 3) == 0 &amp;&amp; (i + 1) * 3 % Width &lt; Width - 1)
                      {
                          ptr += 2;
                      }
              }
                  // Unlock the bits.
              tmp_bitmap.UnlockBits(bmpData);
          }
  </code></pre>
  
  <p>I think posting my code is necessary as it only occurs when such value is set to my method.</p>
  
  <p>I hope you can help me fix this problem.
  Thank you very much in advance!</p>