[英]vshost32-clr2.exe hangs when calling extern function if native code debugging is disabled
The situation: 情况:
In my C# solution (VS 2013) I added a C project. 在我的C#解决方案(VS 2013)中,我添加了一个C项目。 The C project contains a function that is declared in C# with:
C项目包含一个在C#中声明的函数:
[DllImport("My_C_Dll.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void My_C_Function(IntPtr OutputArray, int Input);
The function is called with this code: 使用以下代码调用该函数:
var OutputArray = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UInt16)) * OutputLength);
My_C_Function(OutputArray, Input);
Int16[] ManagedOutputArray= new Int16[OutputLength];
Marshal.Copy(OutputArray, ManagedOutputArray, 0, OutputLength);
Marshal.FreeHGlobal(OutputArray);
The issue: 问题:
When "My_C_Function" is called the application hangs (actually is the Visual Studio Hosting process "vshost32-clr2.exe" that hangs) when ALL the following conditions are satisfied: 当满足以下所有条件时,当调用“My_C_Function”时,应用程序挂起(实际上是挂起的Visual Studio主机进程“vshost32-clr2.exe”):
when I run WITH the debugger attached (starting application from Visual Studio) 我在附带调试器的情况下运行(从Visual Studio启动应用程序)
when I DISABLE the "Enable native code debugging" in the Project properties 当我禁用项目属性中的“启用本机代码调试”时
when I ENABLE the "Enable the Visual Studio hosting process" 当我启用“启用Visual Studio托管过程”时
My idea 我的点子
It seems that "vshost32-clr2.exe" stops working because it is not able to execute the C extern function if the "native code debugging" is disabled. 似乎“vshost32-clr2.exe”停止工作,因为如果禁用“本机代码调试”,它将无法执行C extern函数。 It seems that it needs some feature that is given only when "native code debugging" is enabled.
它似乎需要一些仅在启用“本机代码调试”时才会给出的功能。
My issue seems the same of AccessViolationException goes away when native code debugging is enabled but no one has already answered why this happens. 当启用本机代码调试时 ,我的问题似乎与AccessViolationException相同,但没有人已经回答了为什么会发生这种情况。
My question WHY? 我的问题为什么? For another project I already did a different solution that calls a different C extern functions without such issue (I can leave the "hosting process" enabled and the "native code debugging" disabled without any problem) but I cannot find the difference between the two solutions that leads to this error.
对于另一个项目,我已经做了一个不同的解决方案,调用不同的C外部函数没有这样的问题(我可以启用“托管进程”和“本机代码调试”禁用没有任何问题)但我找不到两者之间的区别导致此错误的解决方案。
Any help would be greatly appreciated! 任何帮助将不胜感激!
By disabling code optimization in c++ project properties->C/C++->Optimization I've been able to find an unhandled exception in c++ code. 通过禁用c ++项目属性中的代码优化 - > C / C ++ - >优化,我已经能够在c ++代码中找到未处理的异常。 After fixing some small memory leaks I managed to make it working even with hosting process active and native code debugging disabled.
在修复了一些小的内存泄漏后,我设法使其工作,即使托管进程处于活动状态并禁用本机代码调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.