消失的SEHException
我有一个 C/C++ DLL。我有 ASP.NET 应用程序使用 P/Invoke 调用此 DLL。有时,其中一个调用会抛出 SEHException
。
现在出于测试目的,我首先使用相同的数据调用该函数。
DllFunctions.MyStructure[] structArray = new DllFunctions.MyStructure[2];
structArray[0].A = 10;
structArray[0].B = 10;
structArray[0].C = 15;
structArray[0].D = 15;
structArray[1].A = 8;
structArray[1].B = 12;
structArray[1].C = 13;
structArray[1].D = 17;
int arraySize = 2;
DllFunctions.MyStructure[] otherArray = new DllFunctions.MyStructure[0];
DllFunction.ProblematicFunction(structArray, arraySize, otherArray, 0);
当我在调试模式下启动应用程序时,有时它会抛出 SEHException
,有时则不会。什么会导致这样的随机行为?
编辑:如果从具有相同数据的 C++ 控制台应用程序调用,该函数可以正常运行。
编辑:P/Invoke 签名
[DllImport("mylib.dll")]
public extern static MyStructure ProblematicFunction(MyStructure[] structs1, int arrayLen1, MyStructure[] structs2, int arrayLen2);
I have a C/C++ DLL. I have and ASP.NET application calling this DLL with P/Invoke. Sometimes one of this calls throws an SEHException
.
Right now for testing purposes I call the function with the same data before anything else.
DllFunctions.MyStructure[] structArray = new DllFunctions.MyStructure[2];
structArray[0].A = 10;
structArray[0].B = 10;
structArray[0].C = 15;
structArray[0].D = 15;
structArray[1].A = 8;
structArray[1].B = 12;
structArray[1].C = 13;
structArray[1].D = 17;
int arraySize = 2;
DllFunctions.MyStructure[] otherArray = new DllFunctions.MyStructure[0];
DllFunction.ProblematicFunction(structArray, arraySize, otherArray, 0);
When I start the application in debug mode sometimes it happens to throw me the SEHException
, sometimes it doesn't. What can cause random looking behaviour like this?
EDIT: The function runs fine if called from a C++ console application with the same data.
EDIT: the P/Invoke signature
[DllImport("mylib.dll")]
public extern static MyStructure ProblematicFunction(MyStructure[] structs1, int arrayLen1, MyStructure[] structs2, int arrayLen2);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调试模式下启动应用程序会禁用低碎片堆 - 您仍然会损坏内存,只是运气好并浪费了一些填充内存。如果您想查看正常行为,请使用 Ctrl-F5 运行应用程序,然后使用另一个 VS 实例附加到进程
Starting an application in Debug mode disables the Low-Fragmentation Heap - you're still corrupting memory, you're just getting lucky and trashing some padding memory. If you want to see the normal behavior, run the app using Ctrl-F5, then Attach To Process with another VS instance