runtime: Asserts not working in WinForms .net Core apps

  • .NET Core Version: 3.1.6.

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

Problem description:

System.Diagnostics.Trace.Assert and System.Diagnostics.Debug.Assert are not working in WInForms .net core apps. Programs are silently crash.

Expected behavior: No crash, and assertion dialog must appear after assert.

Minimal repro: Create new WinForm core project. Put System.Diagnostics.Debug.Assert(false, "test"); anywhere in the code, for example:

protected override void OnShown(EventArgs e)
{
    base.OnShown(e);
    System.Diagnostics.Debug.Assert(false, "test");
}

run project (Debug conf.) with ctrl+f5. P.s. if run with f5 - no crash, but and no assertion dilaog (only message in output).

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (17 by maintainers)

Most upvoted comments

dotnet/coreclr#20764 changed winforms assert behavior. We have a hook which is currently used by debug.assert tests. @danmosemsft is this the hook that winforms should use took hook debug.assert? Adding @merriemcgaw

I think as explained in https://github.com/dotnet/runtime/issues/11461, the Trace_AssertUiEnabledFalse_SkipsFail test illustrates how to use custom Trace Listeners to allow for showing dialogs.

In case System.Diagnostics.Trace.Listeners does not work for WinForms for some reason, we should add a proper public API using standard public API process that does work.

Related / duplicate: #15386 , #11461

We couldn’t pop a msg box at this level any more due to layering. So we treat as a regular failing assert. But I think we added a hook for UI stacks to wire in a dialog. If so then fix is actually in winforms