vshost32.exe crash when calling unmanaged DLL

隐身守侯 提交于 2019-11-28 10:31:01

I had problem with crashes of vshost32.exe the problem vanished when I checked the checkbox:

Properties -> Debug -> Enable unmanaged code debugging

Does it work for you?

EDIT: In more recent versions the option is called: Enable native code debugging (thanks Qwerty01)

EDIT: It also seems to help in VS2008 (@Deacon Frost), VS2010 (@Alxandr).

Not sure but you can disable use of the visual studio hosting process from Properties -> Debug

Might be that there is an unhandled exception. You could try to add the following code to handle all uncatched exceptions:

static void Main()
{
  // Add a handler for the UnhandledExceptionEvent
  AppDomain.CurrentDomain.UnhandledException +=
    new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  Application.Run(new Form1());
}

static void CurrentDomain_UnhandledException
     (object sender, UnhandledExceptionEventArgs e)
{
    try
    {
        Exception ex = (Exception)e.ExceptionObject;

        MessageBox.Show(ex.ToString(), "Error", 
              MessageBoxButtons.OK, MessageBoxIcon.Stop);
    }
    finally
    {
        Application.Exit();  
    }
}

The reason for the underlying problem is that you might have a different working folder when debugging so that your native library is not found.

I am using Visual C# 2010 Express. I was able to stop the vshost32 crashes by navigating to Project -> Properties. I clicked on the Debug tab and unchecked the "Enable the Visual Studio hosting process" checkbox.

download dependency walker http://www.dependencywalker.com/ use it to open up your dll, and see if it relies on other dlls that are not present in that folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!