runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Debug.Assert causing an application to crash.

Open Petermarcu opened this issue 8 years ago • 14 comments

@anpaz-msft commented on Fri Jan 12 2018

Issue Title

Debug.Assert causing an application to crash.

General

Typically, Debug.Assert should bring a pop-up with Abort, Retry, Ignore, or if the assertuienabled property is false then it should just continue, however in version 2.1.2 hitting the assert is causing the app to crash with a FailFast message.

For a simple console app:

using System;
using System.Diagnostics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Debug.Assert(false, "Assert hit");
            Console.WriteLine("Goodbye World!");

        }
    }
}

You get this:

C:\Users\anpaz\source\repos\ConsoleApp1\ConsoleApp1>dotnet run
Hello World!
FailFast: Assert hit

   at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
   at ConsoleApp1.Program.Main(String[] args) in C:\ConsoleApp1\ConsoleApp1\Program.cs:line 11

   at System.Environment.FailFast(System.String, System.Exception)
   at ConsoleApp1.Program.Main(System.String[])

I'm finding this to be problematic in my xUnit tests: when I run the tests and they (purposely) hit a Debug.Assert the run pauses and eventually fails.

> dotnet --version
2.1.2

Petermarcu avatar Jan 14 '18 20:01 Petermarcu

Related to dotnet/runtime#9229 cc @sywhang

jkotas avatar Jan 15 '18 01:01 jkotas

This is also related to dotnet/runtime#8281 , where we finished our side of the work but still VS has its end to complete. Without being able to attach a debugger, then the only thing left to do seems to exit, as it happens now. If we can complete the work to attach the debugger with the VS team, then we should enforce that behavior, as it happens on Desktop. Concerns/suggestions?

lt72 avatar Jan 17 '18 01:01 lt72

I have a branch I'm working on to fix dotnet/runtime#9229, which adds another FailFast method and Fcall with an additional argument to differentiate the source of error, and distinguish the message printed from FailFast Fcall.

As far as this issue is concerned, since the call to Environment.FailFast is what's causing the application to crash, I think we could just use that additional parameter to determine whether we should stop the runtime from crashing.

sywhang avatar Jan 17 '18 01:01 sywhang

The behavior in .net framework is controlled by the DefaultTraceListener, which is automatically added to the Trace.Listeners and Debug.Listeners. I imagine the Fail() method of the TraceListner gets triggered by the Debug.Assert and this is the one that should be calling FailFast. So, what happens when a Debug.Assert is hit can be controlled by the application. The behavior that I see is in .net core that Debug.Assert is the one calling FailFast directly though, as even when I explicitly remove all listeners the app still crashes, is there any reason to change this behavior? I suppose that until the VS integration is complete the behavior can remain to crash the app, but there should at least be the option to customize this behavior by changing the list of Trace/Debug Listeners as in .net framework.

anpaz avatar Jan 17 '18 02:01 anpaz

Assigning this to Mike since he is already working on dotnet/runtime#8281

lt72 avatar Jan 19 '18 00:01 lt72

@caslan: do you think this can make it for 2.1? Preview2 is out end of this month, but likely still actionable for later preview...

lt72 avatar Mar 19 '18 22:03 lt72

This should now be working as expected with the latest d15.7stg and dotnet 2.1.2-preview-007474. Closing on behalf of @caslan. @mikem8361 FYI.

lt72 avatar Mar 20 '18 16:03 lt72

@caslan, @gregg-miskelly how do outside devs get d15.7stg? Can they? I have another issue dotnet/coreclr#16776 that I really think it will be fix. He has already tried a recent runtime build (2.1.0-preview3-26319-04) and still hits the same exception when using mixed mode debugging on .NET Core. He is using the sample host (see the issue) but I tried it myself with the sample host, last runtime bits from master and VS preview 27517.d15.7 and it works.

mikem8361 avatar Mar 20 '18 19:03 mikem8361

@wardengnaw, can you double check if 15.7 Preview 1 has your changes?

caslan avatar Mar 20 '18 20:03 caslan

15.7 Preview 1 has my changes

WardenGnaw avatar Mar 20 '18 20:03 WardenGnaw

Here is the download location for the Visual Studio preview channel: https://www.visualstudio.com/vs/preview/

gregg-miskelly avatar Mar 20 '18 20:03 gregg-miskelly

@lt72 above claimed to close this. Actually doing so now : )

noahfalk avatar Mar 27 '18 05:03 noahfalk

I'm on netcore3.1 using VS16.4 and still (since months) see dying everything unrecoverable just because ONE SINGLE Debug.Assert somewhere in my code. Even if I attach VS there is no way to continue and ignore the assertion. There were no such problems using .NET 2.0/3.0/3.5/4.0/4.5/4.51/4.52/4.6/4.61/4.62/4.63/4.7/4.71/4.72/4.8 in the past.

springy76 avatar Dec 10 '19 11:12 springy76

@springy76 Could you please open a new issue about this using "Help / Send Feedback / Report a Problem"?

jkotas avatar Dec 10 '19 13:12 jkotas