From bf763fe5896898b27551113ae8023cba974da7c3 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 26 May 2025 15:06:26 +0200 Subject: [PATCH 1/2] fix: respect SentryNative=false at runtime --- CHANGELOG.md | 1 + src/Sentry/Internal/DebugStackTrace.cs | 4 ++++ .../Platforms/Native/buildTransitive/Sentry.Native.targets | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bdb09f65d..e0a819ad78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Support musl on Linux ([#4188](https://github.com/getsentry/sentry-dotnet/pull/4188)) - Support for Windows ARM64 with Native AOT ([#4187](https://github.com/getsentry/sentry-dotnet/pull/4187)) - Addressed potential performance issue with Sentry.Maui ([#4219](https://github.com/getsentry/sentry-dotnet/pull/4219)) +- Respect `SentryNative=false` at runtime ([#4220](https://github.com/getsentry/sentry-dotnet/pull/4220)) ## 5.8.0 diff --git a/src/Sentry/Internal/DebugStackTrace.cs b/src/Sentry/Internal/DebugStackTrace.cs index 3f43297772..81d1afea90 100644 --- a/src/Sentry/Internal/DebugStackTrace.cs +++ b/src/Sentry/Internal/DebugStackTrace.cs @@ -260,6 +260,10 @@ private IEnumerable CreateFrames(StackTrace stackTrace, bool i #elif __IOS__ || MACCATALYST _nativeDebugImages ??= Sentry.Cocoa.C.LoadDebugImages(_options.DiagnosticLogger); #else + if (!SentryNative.IsAvailable) + { + _nativeDebugImages ??= new(); + } _nativeDebugImages ??= Sentry.Native.C.LoadDebugImages(_options.DiagnosticLogger); #endif diff --git a/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets b/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets index 3e08ba467f..90ccbdc0d6 100644 --- a/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets +++ b/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets @@ -13,8 +13,8 @@ From a8fbd22ac729191f1ca71a8e7da0cc0de47def36 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 26 May 2025 12:22:14 +0200 Subject: [PATCH 2/2] integration-test: dotnet publish -p:SentryNative=true/false --- integration-test/runtime.Tests.ps1 | 37 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/integration-test/runtime.Tests.ps1 b/integration-test/runtime.Tests.ps1 index 047b5e9594..9f22d10cb4 100644 --- a/integration-test/runtime.Tests.ps1 +++ b/integration-test/runtime.Tests.ps1 @@ -68,6 +68,20 @@ internal class FakeTransport : ITransport } } + function publishConsoleApp([bool]$SentryNative = $true) + { + dotnet publish console-app ` + -c Release ` + --nologo ` + --framework $framework ` + -p:SentryNative=$($SentryNative.ToString().ToLower()) ` + | ForEach-Object { Write-Host $_ } + if ($LASTEXITCODE -ne 0) + { + throw 'Failed to publish the test app project.' + } + } + function runConsoleApp([bool]$IsAOT = $true, [string]$CrashType = 'Managed', [string]$Dsn = 'http://key@127.0.0.1:9999/123') { if ($IsAOT) @@ -75,11 +89,7 @@ internal class FakeTransport : ITransport $executable = getConsoleAppPath If (!(Test-Path $executable)) { - dotnet publish console-app -c Release --nologo --framework $framework | ForEach-Object { Write-Host $_ } - if ($LASTEXITCODE -ne 0) - { - throw 'Failed to publish the test app project.' - } + publishConsoleApp } } else @@ -90,7 +100,7 @@ internal class FakeTransport : ITransport Write-Host "::group::Executing $executable" try { - Invoke-Expression $executable | ForEach-Object { + Invoke-Expression "$executable 2>&1" | ForEach-Object { Write-Host " $_" $_ } @@ -120,8 +130,19 @@ internal class FakeTransport : ITransport "console-app$exeExtension", "console-app$debugExtension") | Sort-Object -Unique) } - It "'dotnet publish' produces an app that's recognized as AOT by Sentry" { - runConsoleApp | Should -AnyElementMatch 'This looks like a Native AOT application build.' + It "'dotnet publish' produces an app that's recognized as AOT by Sentry (SentryNative=<_>)" -ForEach @($false, $true) { + publishConsoleApp $_ + $output = runConsoleApp + $output | Should -AnyElementMatch 'This looks like a Native AOT application build.' + $output | Should -Not -AnyElementMatch 'System.DllNotFoundException: Unable to load (shared library|DLL) ''sentry-native'' or one of its dependencies' + if ($_) + { + $output | Should -AnyElementMatch 'Initializing sentry native' + } + else + { + $output | Should -Not -AnyElementMatch 'Initializing sentry native' + } } It "'dotnet run' produces an app that's recognized as JIT by Sentry" {