xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.49k stars 515 forks source link

Any (even wrapped at try..catch) exception at .net9-macos TFM terminates application in debug build configuration #21705

Open yevgeny-sotnikov opened 4 days ago

yevgeny-sotnikov commented 4 days ago

Apple platform

macOS

Framework version

net9.0-*

Affected platform version

.net 9.0.100

Description

In debug build app instantly crashes even on expected exceptions wrapped to try-catch block.

No any information neither in debug output, nor at AppDomain.CurrentDomain.UnhandledException handler.

App crashes without any notification what's happening. On real project it's real problem cuz it blocks development

Steps to Reproduce

  1. Pull https://github.com/yevgeny-sotnikov/dotnet-issues
  2. Checkout macos-instant-crash-in-debug-config branch
  3. Run sample app

Did you find any workaround?

No

Relevant logs

No response

rolfbjarne commented 2 days ago

I can't reproduce any crashes.

I build like this:

$ dotnet build

and then I run from the command line like this:

$ ./bin/Debug/net9.0-macos/osx-arm64/macOSApp1.app/Contents/MacOS/macOSApp1
2024-11-29 22:10:40.716 macOSApp1[39062:3937935] Microsoft.macOS: Invalid IDE Port: -1
2024-11-29 22:10:41.397 macOSApp1[39062:3937904] WARNING: Secure coding is automatically enabled for restorable state! However, not on all supported macOS versions of this application. Opt-in to secure coding explicitly by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState:.
macOSApp1.MyException: I want to get this exception at least at console output, also, i need to handle this exception - app shouldn't crash
   at macOSApp1.AppDelegate.DidFinishLaunching(NSNotification notification) in [...]/dotnet-issues/macOSApp1/AppDelegate.cs:line 14

and the app doesn't crash.

How are you launching the app?

yevgeny-sotnikov commented 1 day ago

How are you launching the app?

I'm running debug build at Rider/VSCode, doesn't matter, with attached debugger. The problem is when execution reaches exception throwing - after that app instantly stops execution and debugger never reach breakpoint at catch block.

Screenshot 2024-11-30 at 11 28 55

By now in this small sample i know what is root cause of such behaviour, but in real, big solution i spent few hours to find root cause, cuz no any information about exception in debug output. To be honest - at this case app mustn't crash at all cuz exception is catched

With .net8 i don't have such issue - all works as expected