Runtime: Asserts not working in WinForms .net Core apps

Created on 6 Aug 2020  路  19Comments  路  Source: dotnet/runtime

  • .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).

area-System.Diagnostics.Tracing

All 19 comments

@danmosemsft @ericstj do you know of any changes in .NET Runtime that could affect this?

Can you get a call stack?

net472 - gives the assert message box:

    [Managed to Native Transition]      Annotated Frame
    System.dll!Microsoft.Win32.SafeNativeMethods.MessageBox(System.IntPtr hWnd, string text, string caption, int type)  Unknown No symbols loaded.
    System.dll!System.Diagnostics.AssertWrapper.ShowMessageBoxAssert(string stackTrace, string message, string detailMessage)   Unknown No symbols loaded.
    System.dll!System.Diagnostics.DefaultTraceListener.Fail(string message, string detailMessage)   Unknown No symbols loaded.
    System.dll!System.Diagnostics.TraceInternal.Fail(string message = "test")   Unknown No symbols loaded.
    System.dll!System.Diagnostics.Debug.Assert(bool condition, string message)  Unknown No symbols loaded.
>   ge-rtb-links.exe!ge_rtb_links.Form1.OnClick(System.EventArgs e = {X = 524 Y = 113 Button = Left}) Line 49   C#  Symbols loaded.

net5.0 - doesn't:

>   System.Private.CoreLib.dll!System.Diagnostics.DebugProvider.FailCore(string stackTrace, string message, string detailMessage, string errorSource)   Unknown No symbols loaded.
    System.Private.CoreLib.dll!System.Diagnostics.DebugProvider.Fail(string message, string detailMessage)  Unknown No symbols loaded.
    System.Private.CoreLib.dll!System.Diagnostics.Debug.Assert(bool condition, string message)  Unknown No symbols loaded.
    ge-rtb-links.dll!ge_rtb_links.Form1.OnClick(System.EventArgs e = {X = 607 Y = 190 Button = Left}) Line 49   C#  Symbols loaded.

We couldn鈥檛 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

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Related / duplicate: #15386 , #11461

@jkotas @danmosemsft
So, if I understand right, this:

what work remains here? Is it only for Winforms/WPF to hook it up to a dialog? If so I think we can close this, and ensure they have issues in their repos to do that.

did not happen (until now)? And this issue must be transferred back to WinForms repo?

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

hook

This hook is internal API. It is not something that WinForms or WPF should be using in the current shape.

System.Diagnostics.Trace.Listeners is the public API for customization of assertion failures.

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.

In case System.Diagnostics.Trace.Listeners does not work for WinForms for some reason

@RussKie @merriemcgaw I think guys here not 100% sure what going on with this in WinForms.
This is nasty regression from .net Framework - not to able using asserts :(

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.

/cc: @OliaG @diverdan92

@RussKie do you have a 5.0 issue where you're investigating TraceListener fix?

Perhaps you could open a similar issue for WPF and we can close this one?

Aye, will do.

Issue was "moved" to dotnet/wpf; closing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jchannon picture jchannon  路  3Comments

matty-hall picture matty-hall  路  3Comments

bencz picture bencz  路  3Comments

nalywa picture nalywa  路  3Comments

v0l picture v0l  路  3Comments