From 0087cf38f24816f1a40dc4e09bcc95dd37811846 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Wed, 22 Jan 2025 22:03:06 +1300 Subject: [PATCH 1/4] Don't set MarshalManagedExceptionMode.UnwindNativeCode for CoreCLR --- .../buildTransitive/Sentry.Bindings.Cocoa.targets | 13 +++++++++++++ src/Sentry/Platforms/Cocoa/SentrySdk.cs | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Sentry.Bindings.Cocoa/buildTransitive/Sentry.Bindings.Cocoa.targets b/src/Sentry.Bindings.Cocoa/buildTransitive/Sentry.Bindings.Cocoa.targets index 4b74ad10fe..6a61d17577 100644 --- a/src/Sentry.Bindings.Cocoa/buildTransitive/Sentry.Bindings.Cocoa.targets +++ b/src/Sentry.Bindings.Cocoa/buildTransitive/Sentry.Bindings.Cocoa.targets @@ -49,4 +49,17 @@ + + + --marshal-managed-exceptions=unwindnativecode + + diff --git a/src/Sentry/Platforms/Cocoa/SentrySdk.cs b/src/Sentry/Platforms/Cocoa/SentrySdk.cs index c7b438f12d..bf2feb5744 100644 --- a/src/Sentry/Platforms/Cocoa/SentrySdk.cs +++ b/src/Sentry/Platforms/Cocoa/SentrySdk.cs @@ -1,6 +1,8 @@ using Sentry.Cocoa; using Sentry.Cocoa.Extensions; using Sentry.Extensibility; +using Sentry.Internal; +using Sentry.PlatformAbstractions; // ReSharper disable once CheckNamespace namespace Sentry; @@ -10,10 +12,10 @@ public static partial class SentrySdk private static void InitSentryCocoaSdk(SentryOptions options) { options.LogDebug("Initializing native SDK"); - // Workaround for https://github.com/xamarin/xamarin-macios/issues/15252 ObjCRuntime.Runtime.MarshalManagedException += (_, args) => { - args.ExceptionMode = ObjCRuntime.MarshalManagedExceptionMode.UnwindNativeCode; + // This MAY be overriden in Sentry.Bindings.Cocoa.targets + options.LogDebug($"MarshalManagedExceptionMode: {args.ExceptionMode}"); }; // Set default release and distribution From f98139e27f9c68ffbe8491907d397f73760c03c5 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Wed, 22 Jan 2025 22:29:23 +1300 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f47b834bdc..e3101e6c83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - .NET on iOS: Add experimental EnableAppHangTrackingV2 configuration flag to the options binding SDK ([#3877](https://github.com/getsentry/sentry-dotnet/pull/3877)) - Added `SentryOptions.DisableSentryHttpMessageHandler`. Useful if you're using `OpenTelemetry.Instrumentation.Http` and ending up with duplicate spans. ([#3879](https://github.com/getsentry/sentry-dotnet/pull/3879)) +### Fixes + +- Use MarshalManagedExceptionMode.Default on CoreCLR ([#3912](https://github.com/getsentry/sentry-dotnet/pull/3912)) + ### Dependencies - Bump Native SDK from v0.7.17 to v0.7.18 ([#3891](https://github.com/getsentry/sentry-dotnet/pull/3891)) From af44da584e5419149afd6058a0da282c0522c1e2 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 23 Jan 2025 16:08:43 +1300 Subject: [PATCH 3/4] Update Sentry.Bindings.Cocoa.targets --- .../buildTransitive/Sentry.Bindings.Cocoa.targets | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Sentry.Bindings.Cocoa/buildTransitive/Sentry.Bindings.Cocoa.targets b/src/Sentry.Bindings.Cocoa/buildTransitive/Sentry.Bindings.Cocoa.targets index 6a61d17577..6e929b5136 100644 --- a/src/Sentry.Bindings.Cocoa/buildTransitive/Sentry.Bindings.Cocoa.targets +++ b/src/Sentry.Bindings.Cocoa/buildTransitive/Sentry.Bindings.Cocoa.targets @@ -52,13 +52,11 @@ - + --marshal-managed-exceptions=unwindnativecode From 053cf64ffe8687d145efd2e909f95a09b2b7d51b Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Tue, 28 Jan 2025 16:34:05 +1300 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3101e6c83..d3f3261543 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ### Fixes -- Use MarshalManagedExceptionMode.Default on CoreCLR ([#3912](https://github.com/getsentry/sentry-dotnet/pull/3912)) +- MarshalManagedExceptionMode.Default is now used when capturing native exceptions in AOT compiled iOS applications, making native stack traces more readable ([#3912](https://github.com/getsentry/sentry-dotnet/pull/3912)) ### Dependencies