知道什么会导致 Visual Studio 2013 年 "vshost32.exe has stopped working" 吗?

Any idea what can cause "vshost32.exe has stopped working" in Visual Studio 2013?

我正在处理的 C# WPF 应用程序包含许多对非托管外部 DLL 的调用。当 运行 应用程序正常时(即在 Visual Studio 调试器之外),对 DLL 的所有调用都按预期工作。然而,当从 Visual Studio 2013 中调试时,调用 DLL 中的一个特定方法会使应用程序崩溃:

这是我导入方法的方式:

[DllImport("Client.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern string ClientGetVersion();

...这就是我调用 DLL 方法的方式:

try
{
  version = ClientGetVersion();
}
catch (Exception ex)
{
  // Error handling omitted for clarity...
}

似乎 Visual Studio 在调试会话 (VSHOST - the Hosting Process). Furthermore, "Calls to certain APIs can be affected when the hosting process is enabled. In these cases, it is necessary to disable the hosting process to return the correct results." (See the MSDN article How to: Disable the Hosting Process) 期间使用 vshost32.exe 进程来托管应用程序。在 Project > Properties... > Debug 中禁用 "Enable the Visual Studio hosting process" 选项,如下所示,确实解决了问题:

有没有人知道具体是什么导致了“...调用特定 API...”的问题?

vshost32.exe错误是由错误的DllImport语句引起的-外部DLL的return类型不能是string,必须是IntPtr。

这是更正后的代码:

[DllImport("Client.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr ClientGetVersion();

...这是对 DLL 方法的修改调用:

string version;

try
{
  version = Marshal.PtrToStringAnsi(ClientGetVersion());

}
catch (Exception ex)
{
  // Error handling omitted for clarity...
}

感谢@HansPassant 的回答。

退出 Visual Studio 并以管理员模式重新启动。有用!!!