Can I force Windows create a Local Dump of a crashing .NET application?

661 Views Asked by At

I want to make Windows Error reporting write out a crash-dump file when my .NET 5/WPF application crashes. I found an article on it here:

https://learn.microsoft.com/en-us/windows/win32/wer/collecting-user-mode-dumps

but unfortunately that same article says

Applications that do their own custom crash reporting, including .NET applications, are not supported by this feature.

Does this mean that this will not ever work for .NET applications or that it will not work for .NET applications that do their own crash reporting?

Because I've tried to make my app catch unhandled exceptions:

    AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
    TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;
    DispatcherUnhandledException               += App_OnDispatcherUnhandledException;

But none of these handlers seems to be called.

1

There are 1 best solutions below

1
FireEmerald On

The Windows Error Reporting (WER) can be en-/disabled for various scopes by the user. This means even when you trigger the WER correctly, it may does not write any dumps.

You will find enough results how to enable WER via google, one way is via registry keys located at:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps]
-> DumpFolder
-> DumpCount
-> DumpType

Once you enabled WER you need to trigger it from your (.NET) application. This can be done using the Environment.FailFast() method. A example powershell script which triggers WERs dump creation can be found here on stackoverflow.