This is just a quick reminder why Environment.FailFast
may not generate a mini dump on Windows.
It only does that, when the Windows Error Reporting Service (WerSvc
) is not disabled.
Additionally, registry entries could disable WER, even if the service is not disabled.
The following C# [1] code checks if WER is enabled.
/// <summary>
/// Checks if Windows Error Reporting (WER) is currently enabled.
/// </summary>
/// <returns>
/// <c>true</c> enabled, <c>false</c> if not.
/// </returns>
public static bool IsWerEnabled()
{
const string WerBaseKey = @"Software\Microsoft\Windows\Windows Error Reporting";
if (Registry.CurrentUser.GetBooleanValue(WerBaseKey, "Disabled") ||
Registry.LocalMachine.GetBooleanValue(WerBaseKey, "Disabled"))
{
return false;
}
using (var sc = new ServiceController("WerSvc"))
{
// Technically, the service has a start type of "Manual (Trigger Start)",
// but other non-disabled start types (like Automatic) work as well.
return sc.StartType != ServiceStartMode.Disabled;
}
}
The CLR will also generate a mini dump on an uncaught exception. This, however, does not
depend on WER, but is handled by the CLR internally. For .NET Core the CLR will launch
the external createdump.exe
tool (either in the .NET shared directory or in your
bin directory if you build self contained).
[1] GetBooleanValue
is a simple extension method:
public static bool GetBooleanValue(this RegistryKey key, string subkeyName, string value)
{
using (var subKey = key.OpenSubKey(subkeyName))
{
if (subKey != null)
{
object obj = subKey.GetValue(value);
if (obj is int)
{
return ((int)obj) != 0;
}
}
}
return false;
}