请教一个C#生成dump文件的问题
参照一个帖子:http://www.111cn.net/net/33/bae2af56ee02cd99daba9a078a311107.htm
具体内容是
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace MiniDump
...{
class Program
...{
static void Main(string[] args)
...{
try
...{
string a = "";
a = null;
if (a.ToString() == "1")
Console.WriteLine("a is 1");
}
catch
...{
MiniDump.TryDump("c:MiniDmp.dmp", MiniDump.MiniDumpType.WithFullMemory);
}
Console.ReadKey();
}
}
/**//// <summary>
/// 该类要使用在windows 5.1 以后的版本,如果你的windows很旧,就把Windbg里面的dll拷贝过来,一般都没有问题
/// DbgHelp.dll 是windows自带的 dll文件 。
/// </summary>
public static class MiniDump
...{
/**//*
* 导入DbgHelp.dll
*/
[DllImport("DbgHelp.dll")]
private static extern Boolean MiniDumpWriteDump(
IntPtr hProcess,
Int32 processId,
IntPtr fileHandle,
MiniDumpType dumpType,
ref MinidumpExceptionInfo excepInfo,
IntPtr userInfo,
IntPtr extInfo );
/**//*
* MINIDUMP_EXCEPTION_INFORMATION 这个宏的信息
*/
struct MinidumpExceptionInfo
...{
public Int32 ThreadId;
public IntPtr ExceptionPointers;
public Boolean ClientPointers;
}
/**//*
* 自己包装的一个函数
*/
public static Boolean TryDump(String dmpPath, MiniDumpType dmpType)
...{
//使用文件流来创健 .dmp文件
using (FileStream stream = new FileStream(dmpPath, FileMode.Create))
...{
//取得进程信息
Process process = Process.GetCurrentProcess();
// MINIDUMP_EXCEPTION_INFORMATION 信息的初始化
MinidumpExceptionInfo mei = new MinidumpExceptionInfo();
mei.ThreadId = Thread.CurrentThread.ManagedThreadId;
mei.ExceptionPointers = Marshal.GetExceptionPointers();
mei.ClientPointers = true;
//这里调用的Win32 API
Boolean res = MiniDumpWriteDump(
process.Handle,
process.Id,
stream.SafeFileHandle.DangerousGetHandle(),
dmpType,
ref mei,
IntPtr.Zero,
IntPtr.Zero);
//清空 stream
stream.Flush();
stream.Close();
return res;
}
}
public enum MiniDumpType
...{
None = 0x00010000,
Normal = 0x00000000,
WithDataSegs = 0x00000001,
WithFullMemory = 0x00000002,
WithHandleData = 0x00000004,
FilterMemory = 0x00000008,
ScanMemory = 0x00000010,
WithUnloadedModules = 0x00000020,
WithIndirectlyReferencedMemory = 0x00000040,
FilterModulePaths = 0x00000080,
WithProcessThreadData = 0x00000100,
WithPrivateReadWriteMemory = 0x00000200,
WithoutOptionalData = 0x00000400,
WithFullMemoryInfo = 0x00000800,
WithThreadInfo = 0x00001000,
WithCodeSegs = 0x00002000
}
}
}
以上是示例代码,可是当出异常后,再跑到这个MiniDumpWriteDump函数时,提示
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
请问这是什么原因呀?
C#还有什么方式,能自动生成程序Crash的dump文件呢? --------------------编程问答-------------------- http://topic.csdn.net/u/20100913/19/ecc693ab-3464-4dc5-b1c0-4dd89ceedef4.html
这是一个参考的帖子,
求教呀! --------------------编程问答-------------------- windebug +sos.dll。
看看。
这里有本书专业.net 调试的。
http://www.teilihua.com/shu26.aspx --------------------编程问答-------------------- 参考http://topic.csdn.net/u/20100913/19/ecc693ab-3464-4dc5-b1c0-4dd89ceedef4.html --------------------编程问答-------------------- 没搞出来,往上搜得代码,用C#实现的不理想,用C++的跑不起来.
请问哪位高手有可以运行的代码给与参考吗?麻烦给出源代码下载地址,谢谢了. --------------------编程问答-------------------- 怎么还是没有回复呀,继续求教中... --------------------编程问答-------------------- mark
http://www.codeproject.com/Articles/502658/Getting-info-from-NET-applications-in-production --------------------编程问答-------------------- ...{
MiniDump.TryDump("c:MiniDmp.dmp", MiniDump.MiniDumpType.WithFullMemory);
}
你保存的文件路径都打错了
补充:.NET技术 , C#