ClrDump – Create small minidumps of .NET applications

New tool on my web site: ClrDump (Beta)

ClrDump is an experimental set of tools that allow to produce small minidumps of managed applications. In the past, it was necessary to use full dumps (very large in size) if you needed to perform post-mortem analysis of a .NET application. ClrDump can produce small minidumps that contain enough information to recover the call stacks of all threads in the application. It supports .NET runtime versions 1.1 and 2.0.


8 thoughts on “ClrDump – Create small minidumps of .NET applications”

  1. Good to see you at


    You are a very famous mvp in the microsoft newsgroup, aren’t you?

    Your samples are very helpful. I just want to say thank you.

  2. I am simply calling

    int ret = RegisterFilter(filePath, MINIDUMP_TYPE.MiniDumpWithDataSegs) and the error I get is “1004 – Invalid flags. filePath is a full file path with file name. What could be wrong…? I am on dbghelp.dll version 6.6.35 – just came out.

    I have a .net app.

    I have:
    [DllImport(“clrdump.dll”, CharSet = CharSet.Unicode)]
    public static extern int RegisterFilter(string FileName, uint DumpType);

    and mini dump type as – per Microsoft:
    public const uint MiniDumpNormal = 0x00000000;
    public const uint MiniDumpWithDataSegs = 0x00000001;
    public const uint MiniDumpWithFullMemory = 0x00000002;
    public const uint MiniDumpWithHandleData = 0x00000004;
    public const uint MiniDumpFilterMemory = 0x00000008;
    public const uint MiniDumpScanMemory = 0x00000010;
    public const uint MiniDumpWithUnloadedModules = 0x00000020;
    public const uint MiniDumpWithIndirectlyReferencedMemory = 0x00000040;
    public const uint MiniDumpFilterModulePaths = 0x00000080;
    public const uint MiniDumpWithProcessThreadData = 0x00000100;
    public const uint MiniDumpWithPrivateReadWriteMemory = 0x00000200;
    public const uint MiniDumpWithoutOptionalData = 0x00000400;
    public const uint MiniDumpWithFullMemoryInfo = 0x00000800;
    public const uint MiniDumpWithThreadInfo = 0x00001000;
    public const uint MiniDumpWithCodeSegs = 0x00002000;

    Any help is appreciated. Also do I have to call SetUnhandledExceptionFilter first before calling RegisterFilter- doesn’t sounds like it but just checking.


  3. You do not have to call SetUnhandledExceptionFilter.

    DbgHelp is a beta version, with some known bugs, so I would recommend to use the released version (6.5.x.x) for production. But it should not affect this problem, since RegisterFilter does not use DbgHelp.dll.

    In order to reproduce the problem with RegisterFilter, I will need a bit more information:
    – What operating system version, service pack, .NET Runtime versions are used?
    – What version of Visual Studio is used?
    – How exactly and when do you get the mentioned error code?
    – It would be good if you could post a small but compilable sample that reproduces the problem (e.g. a small console app).


  4. OS -> WinXP SP2
    .NET 2.0 (v2.0.50727)
    VS 2005

    I get the error when I call GetLastError() after I call “int ret = RegisterFilter(filePath, MINIDUMP_TYPE.MiniDumpWithDataSegs)”.

  5. What was the return value of RegisterFilter? Was it zero or non-zero?

    Also, it is not possible to call GetLastError right after PInvoke call (it will not give correct results). Instead, you should change the function definition to this:

    [DllImport(“clrdump.dll”, CharSet = CharSet.Unicode, SetLastError=true)]
    public static extern int RegisterFilter(string FileName, uint DumpType);

    and use Marshal.GetLastWin32Error to get the last error code. Something like this:

    int ret = RegisterFilter(…);
    if( ret == 0 )
    int error = Marshal.GetLastWin32Error();


  6. ok- we decided that we can’t really put the clrdump.dll into our project due to us being hesitant to have an external dll in our process with inability to own the code (sorry – team policy)… But your work is tremendeously valuable as I’ve seen it in the posts as well as here, so I plead for your help. I am writing .net 2.0 code to use MiniDumpWriteDump() directly. I’ve tried everything I could do pull it off – posts from John Robbins, youself, books, msdn – and i get an error when I call MiniDumpWriteDump() – err = 2 -> canot file the file specified. I noticed that in your CreateDump() call you are not asking for a file handle but rather a file name. I think you know smth I don’t 🙂 I have all the .cs files which clearly show how I SetUnhandledExceptionFilter, the filter function executes, I get exception pointers, create file handle, etc etc for MiniDumpWriteDump()- then call MiniDumpWriteDump() and I get this error (always) – I am using Marshal.GetLastWin32Error(); I am pleading for your help and good will…(can be contacted at Will also try your email with attached files. THANKS!!!

  7. hello everybody
    Now i am creating sample windows application in c#.net2.0 . now i am plan to create dump for all unhandle exception and application exception.
    last 2 week i search in net. i cannot find any solution. i tried adplus but it is dump file size is high.
    now i trying in dbhelp.dll and clrdmp.dll here below i show my code.

    using this i can create dump but using windbg tool i open this dump but does not break in the expection point in development show

    please give me one example how i create minidump in c# windows application for all exception.

    please reply as much as soon


    my source code

    public partial class Form1 : Form
    [DllImport(“clrdump.dll”, CharSet = CharSet.Unicode, SetLastError = true)]
    static extern Int32 CreateDump(Int32 ProcessId, string FileName,
    Int32 DumpType, Int32 ExcThreadId, IntPtr ExtPtrs);

    [DllImport(“clrdump.dll”, CharSet = CharSet.Unicode, SetLastError = true)]
    static extern Int32 RegisterFilter(string FileName, Int32 DumpType);

    public Form1()

    AppDomain.CurrentDomain.UnhandledException +=
    new UnhandledExceptionEventHandler

    private void button1_Click(object sender, EventArgs e)
    // int i = 0, j = 1, k = 0;
    // k = j / i;
    throw new InvalidOperationException(“in valid”);
    private struct MinidumpExceptionInfo
    public int ThreadId;
    public IntPtr ExceptionPointers;
    public bool ClientPointers;
    static void UnhandleExceptionHandler(object sender,
    UnhandledExceptionEventArgs e)

    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);
    CreateDump(process.Id, “DumpTest.vshost.dmp”,0,mei.ThreadId,IntPtr.Zero);
    // RegisterFilter(“Minidump.dmp”, 0);


  8. Hi Oleg,

    thanks a lot for this very good work. I’ve blogged a post on how to create and analyze .net unhandled exception using ClrDump.dll ( In our current product I’m using MiniDumpWriteDump directly and when I analyze with SOS is seems to be ok (I get the stacks but no handle information and so on). Are you doing anything more in ClrDump.dll? Could you just explain the concept?


Leave a Reply

Your email address will not be published. Required fields are marked *