-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] System.Diagnostics.Debug.Assert causing app to crash #113874
Comments
This behavior comes from here: runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/DebugProvider.Unix.cs Lines 18 to 29 in 98b365d
so it looks intentional. That said, what would you expect the behavior to be? In any case, moving to dotnet/runtime, since that's where the code in question resides. |
That sounds intentional to me, it's the normal behavior on desktop platforms too. The asserts are compiled-out in Release builds. |
Thank you for your response guys. My expectations were: In Release builds - asserts are compiled-out. (all good here) In Debug builds: if (Debugger.IsAttached) ===================================================== After reading comments in @rolfbjarne response ("Fail in order to avoid anyone catching an exception and masking an assert failure.") I think it all make sense and just my assumptions/expectations of Debug.Assert were incorrect. Thanks once again, close it. |
Apple platform
iOS
Framework version
net8.0-*
Affected platform version
VS For Mac 17.6.14 / Rider 2024.3.6
Description
Reality:
Call Debug.Assert(false, "Message text"); from AppDelegate or any other place in the iOS app (mine is NET8, NOT MAUI) - app will crash (if debugger is not attached)
Expectations:
app will continue execution without a crash
Steps to Reproduce
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
Message text
---- Assert Long Message ----
at System.Diagnostics.DefaultTraceListener.Fail(String message, String detailMessage)
at System.Diagnostics.TraceInternal.Fail(String message, String detailMessage)
at System.Diagnostics.TraceInternal.TraceProvider.Fail(String message, String detailMessage)
at System.Diagnostics.Debug.Fail(String message, String detailMessage)
at System.Diagnostics.Debug.Assert(Boolean condition, String message, String detailMessage)
at System.Diagnostics.Debug.Assert(Boolean condition, String message)
....... removed.
NOTE: this is not a crash ^^ - it is just output of "new StackTrace(bool fNeedFileInfo).ToString()" called internally in "DefaultTraceListener.Fail"
Did you find any workaround?
WORKAROUND:
As Debug.Assert using "DefaultTraceListener" by default, setting "AssertUiEnabled" property to false fixed the issue.
DefaultTraceListener traceListener = new DefaultTraceListener();
traceListener.AssertUiEnabled = false;
Trace.Listeners.Clear();
Trace.Listeners.Add(traceListener);
Relevant logs
Issue looks identical or at least very close to this issue, despite being on another platform
#40512
The text was updated successfully, but these errors were encountered: