简体   繁体   English

如果禁用本机代码调试,则在调用extern函数时,vshost32-clr2.exe会挂起

[英]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.

相关问题 将C编写的DLL调用到C#中时,vshost32-clr2.exe错误 - Error in vshost32-clr2.exe while invoking C written DLL into C# vshost32-clr2.exe已停止工作[错误模块名称:cdosys.dll,版本:6.6.7601.17514,时间戳:0x4ce7b774] - vshost32-clr2.exe has stopped working [Faulting module name: cdosys.dll, version: 6.6.7601.17514, time stamp: 0x4ce7b774] c#多线程问题/vshost32-clr.exe已停止工作 - c# Multithreading Issue / vshost32-clr.exe has stopped working 调试Matlab生成的DLL时C#VS2012 vshost.exe崩溃 - C# VS2012 vshost.exe crashes when debugging Matlab generated DLL 当我调用 OpenFileDialog 的 ShowDialog 方法时,vshost32.exe 已停止工作 - vshost32.exe has stopped working when I call the ShowDialog method of OpenFileDialog Visual Studio中“ vshost32.exe停止工作”或“致命执行引擎错误” - “vshost32.exe has stopped working” OR “fatal execution engine error” in Visual Studio 我的SVN代码存储库中是否需要bin \\ debug \\ appName.vshost.exe和appName.vshost.manifest? - Do I need the bin\debug\appName.vshost.exe and appName.vshost.manifest in my SVN code repository? 知道什么可能导致“vshost32.exe已停止工作”在Visual Studio 2013中? - Any idea what can cause “vshost32.exe has stopped working” in Visual Studio 2013? c# Get Active Window Text(导致 vshost32.exe 已停止工作) - c# Get Active Window Text (causes vshost32.exe has stopped working) 调用SQL CLR函数时出错 - Error in Calling SQL CLR function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM