dotnet / dotnet/winforms

`Debug.Assert` no longer shows a dialog prompt

Open
#3,739 9 comments 7 reactions 0 assignees View on GitHub
priority-2 tenet-compatibility
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

* .NET Core Version: **.NET Core 3.1 onwards**

* Have you experienced this same bug with .NET Framework?: **No**

**Problem description:**

`System.Diagnostics.Trace.Assert` and `System.Diagnostics.Debug.Assert` no longer trigger a dialog prompts in desktop apps. Instead apps silently silently crash unless have a debugger attached.

As discussed in https://github.com/dotnet/runtime/issues/40512, the assert behavior was changed in dotnet/coreclr#20764, and no longer raises a dialog.
https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.Debug/tests/DebugTestsUsingListeners.cs#L248-L303 illustrates how to implement a custom trace listener, which may act as a basis for a fix.

**Expected behavior:**

No crash, and assertion dialog must appear after assert.

**Minimal repro:**

1. Create new WinForm Core project.
2. Put `System.Diagnostics.Debug.Assert(false, "test");` anywhere in the code, for example:
```cs
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
System.Diagnostics.Debug.Assert(false, "test");
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.