Skip to content

Commit 8b4ac33

Browse files
authored
fix: respect SentryNative=false at runtime (#4220)
* fix: respect SentryNative=false at runtime * integration-test: dotnet publish -p:SentryNative=true/false
1 parent b97aec8 commit 8b4ac33

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Support musl on Linux ([#4188](https://github.com/getsentry/sentry-dotnet/pull/4188))
88
- Support for Windows ARM64 with Native AOT ([#4187](https://github.com/getsentry/sentry-dotnet/pull/4187))
99
- Addressed potential performance issue with Sentry.Maui ([#4219](https://github.com/getsentry/sentry-dotnet/pull/4219))
10+
- Respect `SentryNative=false` at runtime ([#4220](https://github.com/getsentry/sentry-dotnet/pull/4220))
1011

1112
## 5.8.0
1213

integration-test/runtime.Tests.ps1

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,28 @@ internal class FakeTransport : ITransport
6868
}
6969
}
7070

71+
function publishConsoleApp([bool]$SentryNative = $true)
72+
{
73+
dotnet publish console-app `
74+
-c Release `
75+
--nologo `
76+
--framework $framework `
77+
-p:SentryNative=$($SentryNative.ToString().ToLower()) `
78+
| ForEach-Object { Write-Host $_ }
79+
if ($LASTEXITCODE -ne 0)
80+
{
81+
throw 'Failed to publish the test app project.'
82+
}
83+
}
84+
7185
function runConsoleApp([bool]$IsAOT = $true, [string]$CrashType = 'Managed', [string]$Dsn = 'http://[email protected]:9999/123')
7286
{
7387
if ($IsAOT)
7488
{
7589
$executable = getConsoleAppPath
7690
If (!(Test-Path $executable))
7791
{
78-
dotnet publish console-app -c Release --nologo --framework $framework | ForEach-Object { Write-Host $_ }
79-
if ($LASTEXITCODE -ne 0)
80-
{
81-
throw 'Failed to publish the test app project.'
82-
}
92+
publishConsoleApp
8393
}
8494
}
8595
else
@@ -90,7 +100,7 @@ internal class FakeTransport : ITransport
90100
Write-Host "::group::Executing $executable"
91101
try
92102
{
93-
Invoke-Expression $executable | ForEach-Object {
103+
Invoke-Expression "$executable 2>&1" | ForEach-Object {
94104
Write-Host " $_"
95105
$_
96106
}
@@ -120,8 +130,19 @@ internal class FakeTransport : ITransport
120130
"console-app$exeExtension", "console-app$debugExtension") | Sort-Object -Unique)
121131
}
122132

123-
It "'dotnet publish' produces an app that's recognized as AOT by Sentry" {
124-
runConsoleApp | Should -AnyElementMatch 'This looks like a Native AOT application build.'
133+
It "'dotnet publish' produces an app that's recognized as AOT by Sentry (SentryNative=<_>)" -ForEach @($false, $true) {
134+
publishConsoleApp $_
135+
$output = runConsoleApp
136+
$output | Should -AnyElementMatch 'This looks like a Native AOT application build.'
137+
$output | Should -Not -AnyElementMatch 'System.DllNotFoundException: Unable to load (shared library|DLL) ''sentry-native'' or one of its dependencies'
138+
if ($_)
139+
{
140+
$output | Should -AnyElementMatch 'Initializing sentry native'
141+
}
142+
else
143+
{
144+
$output | Should -Not -AnyElementMatch 'Initializing sentry native'
145+
}
125146
}
126147

127148
It "'dotnet run' produces an app that's recognized as JIT by Sentry" {

src/Sentry/Internal/DebugStackTrace.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i
260260
#elif __IOS__ || MACCATALYST
261261
_nativeDebugImages ??= Sentry.Cocoa.C.LoadDebugImages(_options.DiagnosticLogger);
262262
#else
263+
if (!SentryNative.IsAvailable)
264+
{
265+
_nativeDebugImages ??= new();
266+
}
263267
_nativeDebugImages ??= Sentry.Native.C.LoadDebugImages(_options.DiagnosticLogger);
264268
#endif
265269

src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<!-- SentryNative.IsEnabled should result in compile-time constant for trimmed applications -->
1414
<!-- Effectively disabling native library -->
1515
<RuntimeHostConfigurationOption Include="Sentry.Native.IsEnabled"
16-
Condition="'$(SentryNative)' != 'false' and '$(SentryNative)' != 'disable'"
17-
Value="true"
16+
Condition="'$(SentryNative)' == 'false' or '$(SentryNative)' == 'disable'"
17+
Value="false"
1818
Trim="true" />
1919
</ItemGroup>
2020

0 commit comments

Comments
 (0)