Thanks. That got me further. However the stack track doesn't seem to be
correct. I only see what appears to be the unmanaged portion of the stack
track or more likely just a different stack trace based on
Marshal.GetExceptionPointers() grabbing the wrong exception info. For
example, this is what I see in the debugger when the app crashes:
mscorlib.dll!System.Text.StringBuilder::AppendFormat
(System.IFormatProvider provider = null, String* format = "{0}{1}",
System.Object[] args = {Length=1}) + 0x290 bytes
mscorlib.dll!System.String::Format(System.IFormatProvider provider = null,
String* format = "{0}{1}", System.Object[] args = {Length=1}) + 0x8c bytes
mscorlib.dll!System.String::Format(String* format = "{0}{1}",
System.Object arg0 = {System.Int32}) + 0x37 bytes
mscorlib.dll!System.IO.TextWriter::WriteLine(String* format = "{0}{1}",
System.Object arg0 = {System.Int32}) + 0x1c bytes
mscorlib.dll!SyncTextWriter::WriteLine(String* format = "{0}{1}",
System.Object arg0 = {System.Int32}) + 0x26 bytes
mscorlib.dll!System.Console::WriteLine(String* format = "{0}{1}",
System.Object arg0 = {System.Int32}) + 0x22 bytes
MiniDumpTest.exe!MiniDumpTest.Class1.OutputMessage() Line 23 C#
MiniDumpTest.exe!MiniDumpTest.Class1.Main(string[] args = {Length=0}) Line
18 C#
and this is what gets displayed when I load the minidump file (on the same
thread id as above):
kernel32.dll!_RaiseException@16() + 0x50
mscorwks.dll!RaiseTheException() + 0x65
mscorwks.dll!JIT_Throw() + 0x51
02fd9d98()
Here is the relevant code I used:
class Class1
{
[STAThread]
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler
(UnhandleExceptionHandler);
OutputMessage();
}
static void OutputMessage()
{
Console.WriteLine("{0}{1}", 34);
}
private struct MinidumpExceptionInfo
{
public int ThreadId;
public IntPtr ExceptionPointers;
public bool ClientPointers;
}
[DllImport("DbgHelp.dll")]
private static extern bool MiniDumpWriteDump(
IntPtr hProcess, int processId, IntPtr fileHandle,
int dumpType, ref MinidumpExceptionInfo excepInfo,
IntPtr userInfo, IntPtr extInfo);
static void UnhandleExceptionHandler(object sender,
UnhandledExceptionEventArgs e)
{
FileStream stream = new FileStream(@"C:\Temp\MiniDumpTest.dmp",
FileMode.Create, FileAccess.ReadWrite);
Process process = Process.GetCurrentProcess();
MinidumpExceptionInfo mei = new MinidumpExceptionInfo();
mei.ThreadId = AppDomain.GetCurrentThreadId();
mei.ExceptionPointers = Marshal.GetExceptionPointers();
mei.ClientPointers = true;
MiniDumpWriteDump(process.Handle, process.Id, stream.Handle,
0, ref mei, IntPtr.Zero, IntPtr.Zero);
stream.Close();
}
}
Any ideas on how to get this working? An acceptable answer would be to
stop wasting my time trying to get MiniDump to work with managed code if
it is known not to work.
--
Keith
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.