我在我的MiniDumpWriteDump (3.5)项目中复制了基本的C#方法interop。
到目前为止,我已经使用这段代码在UnhandledException事件上注册,在进程关闭之前进行崩溃转储。
在我现在面临的特定场景中,我已经将此函数设置为在其他情况下使用,以获取进程的诊断内存转储。
每当这个函数被调用时(不是从UnhandledException处理程序),它就抛出一个AccessViolationException
下面是MiniDump代码的样子(删除了一些多余的部分):
using (var fs = new System.IO.FileStream(fileName,
System.IO.FileMode.Create,
System.IO.FileAccess.Write,
System.IO.FileShare.None))
{
MiniDumpExceptionInformation exp;
exp.ThreadId = GetCurrentThreadId();
exp.ClientPointers = false;
exp.ExceptionPointers = Marshal.GetExceptionPointers();
bool bRet = MiniDumpWriteDump(
GetCurrentProcess(),
GetCurrentProcessId(),
fs.SafeFileHandle.DangerousGetHandle(),
(uint)dumpType,
ref exp,
IntPtr.Zero,
IntPtr.Zero);
return bRet;
}本机类型的定义如下:
//typedef struct _MINIDUMP_EXCEPTION_INFORMATION {
// DWORD ThreadId;
// PEXCEPTION_POINTERS ExceptionPointers;
// BOOL ClientPointers;
//} MINIDUMP_EXCEPTION_INFORMATION, *PMINIDUMP_EXCEPTION_INFORMATION;
// Pack=4 is important! So it works also for x64!
[StructLayout(LayoutKind.Sequential, Pack = 4)]
struct MiniDumpExceptionInformation
{
public uint ThreadId;
public IntPtr ExceptionPointers;
[MarshalAs(UnmanagedType.Bool)]
public bool ClientPointers;
}发布于 2014-03-26 13:14:11
Marshal.GetExceptionPointers()可能返回IntPtr.Zero (可能在操作系统将异常视为已处理的异常时)。如果是这样的话,您可以尝试将'MiniDumpWriteDump‘的调用放到其他地方。我也遇到了同样的问题,并通过将“MiniDumpWriteDump”放入事件处理程序MiniDumpWriteDump来解决它。
https://stackoverflow.com/questions/13016076
复制相似问题