Marshal.StructureToPtr 使 Visual Studio 崩溃
我正在开发一个自定义调试引擎,当我将我的结构编组到 IntPtr
Visual Studio 崩溃时(正在调试的不是调试器)。
我的结构只不过是:
public struct DocumentContext : IDebugDocumentContext2, IDebugCodeContext2
{
private string _fileName;
//.....Implementation of interfaces
}
我的编组代码看起来像这样:
var documentContext = new DocumentContext(_node.FileName);
var size = Marshal.SizeOf(documentContext);
IntPtr ptrDocContext = Marshal.AllocHGlobal(size);
//This is what is crashing
//I don't have a chance to catch anything, it just craps out
//Event log says faulting dll is nt.dll
Marshal.StructureToPtr(documentContext, ptrDocContext, true);
我错过了什么吗?
I'm working on a custom debug engine and when I marshal my structure to a IntPtr
Visual Studio crashes (the one being debugged not the debugger).
My struct is little more than:
public struct DocumentContext : IDebugDocumentContext2, IDebugCodeContext2
{
private string _fileName;
//.....Implementation of interfaces
}
My marshalling code looks like this:
var documentContext = new DocumentContext(_node.FileName);
var size = Marshal.SizeOf(documentContext);
IntPtr ptrDocContext = Marshal.AllocHGlobal(size);
//This is what is crashing
//I don't have a chance to catch anything, it just craps out
//Event log says faulting dll is nt.dll
Marshal.StructureToPtr(documentContext, ptrDocContext, true);
Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果以前从未分配过非托管结构,则不应使用deleteOld。 deleteOld 仅适用于覆盖以前的结构(例如,为了释放字符串引用)。这应该有效:
You should not use deleteOld if the unmanaged structure was never previously allocated. deleteOld is only applicable when you're overwriting a previous structure (so as to deallocate string references, for example.) This should work: