3

I'm creating a WinForm Application in C# using Visual Studio 2012 and I'm getting an error when I debug it :

vshost32-clr2.exe has stopped working

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 :

Properties -> Debug -> Enable unmanaged code debugging

Source : vshost32.exe crash when calling unmanaged DLL

Additional Details :

  • My project doesn't use any DLL.

  • As far as I progress in my project, it only occurs when the width is 17.

I use the following 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 < 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 && (i + 1) * 3 % Width < Width - 1)
                    {
                        ptr += 2;
                    }
            }
                // Unlock the bits.
            tmp_bitmap.UnlockBits(bmpData);
        }

I think posting my code is necessary as it only occurs when such value is set to my method.

I hope you can help me fix this problem. Thank you very much in advance!

Community
  • 1
  • 1
CudoX
  • 985
  • 2
  • 19
  • 31

4 Answers4

2

Not sure if this is the same issue, but I had a very similar issue which resolved (vanished) when I un-checked "Enable the Visual Studio hosting process" under the Debug section of Project/Properties. I also enabled native code debugging.

CarlH
  • 568
  • 5
  • 16
1

This issue can be related with debugging application as "Any CPU" under x64 OS, set Target CPU as x86

volody
  • 6,946
  • 3
  • 42
  • 54
0

Adding my 2 cents since I ran into this today.

In my case, a call to a printer was passing some invalid value, and it seems it send the debugger to sleep with the fishes.

If you run into this, see if you can pinpoint the line and make sure there are no funny business issues around a call out (like a printing service)

Noctis
  • 11,507
  • 3
  • 43
  • 82
0

Below solution worked for me:

  1. Go to the Project->Properties->Debug tab
  2. Unchecked the 'Enable the Visual Studio hosting process' checkbox
  3. Checked 'Enable native code debugging' option

Hope this helps.

ps2340256
  • 51
  • 3