Visual Studio 2012 - vshost32-clr2.exe已停止工作

3
我正在使用Visual Studio 2012和C#创建一个WinForm应用程序,调试时出现了错误:
vshost32-clr2.exe has stopped working

我已经搜索过了,但大部分结果都是针对Visual Studio 2010及以下版本的,并且我得到了类似的解决方案,我认为这不适用于Visual Studio 2012:

Properties -> Debug -> Enable unmanaged code debugging

来源: 调用非托管DLL时vshost32.exe崩溃

附加细节:

  • 我的项目没有使用任何DLL。

  • 在我的项目中,只有当宽度为17时才会发生。

我使用以下代码:

        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);
        }

我认为发布我的代码是必要的,因为只有在将此值设置为我的方法时才会出现此问题。

我希望你能帮助我解决这个问题。 非常感谢您提前的帮助!

4个回答

2

不确定是否是同一个问题,但我遇到了非常相似的问题。当我在项目/属性的调试部分取消选中“启用Visual Studio托管进程”并启用本机代码调试时,问题得到了解决(消失)。


1
此问题可能与在x64操作系统下将应用程序调试设置为“Any CPU”,并将目标CPU设置为x86有关。

0

分享我的经验,因为今天我遇到了这个问题。

在我的情况下,对打印机的调用传递了一些无效值,似乎导致调试器崩溃。

如果你遇到了这个问题,请尝试定位代码行,并确保没有任何有关调用外部服务(如打印服务)的问题。


0

以下解决方案适用于我:

  1. 进入项目->属性->调试选项卡
  2. 取消选中“启用Visual Studio托管进程”复选框
  3. 选中“启用本机代码调试”选项

希望这可以帮到你。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接