Skip to content

Conversation

@jpnurmi
Copy link
Collaborator

@jpnurmi jpnurmi commented Jun 19, 2025

This PR fixes a regression introduced by #4275: the _SentryIsNet8OrGreater helper property was not correctly evaluated when publishing AOT, and Sentry was used as a NuGet package.

The newly introduced integration test creates a minimal AOT app out of the tree in the system temp directory, and tests both PublishAot and also PublishContainer on Linux with Docker available.

Fixes: #4296

@jpnurmi jpnurmi changed the title WIP: Native AOT linking WIP: fix: Native AOT linking Jun 20, 2025
@jpnurmi jpnurmi changed the title WIP: fix: Native AOT linking fix: Native AOT linking Jun 20, 2025
@jpnurmi jpnurmi marked this pull request as ready for review June 20, 2025 14:44
@bruno-garcia bruno-garcia requested a review from vaind June 20, 2025 15:01
@jpnurmi
Copy link
Collaborator Author

jpnurmi commented Jun 20, 2025

Background:

As you might notice from the commit history, I started with trying to make the existing integration test fail but eventually gave up. Since I had a set of commands (#4296 (comment)) I was able to use to reproduce the error locally, I decided to try running those in the CI. First, directly in the workflow for Linux, then as a manual test script for all platforms, and finally, I turned it into a Pester test script.

The second last commit shows what kind of failures the new integration test produces when the properties are not correctly evaluated:

ubuntu-22.04 (linux-x64)
Describing Publish
  Determining projects to restore...
  Restored /tmp/0xsgwocv.qfm/hello-sentry.csproj (in 1.34 sec).
  hello-sentry -> /tmp/0xsgwocv.qfm/bin/Release/net9.0/linux-x64/hello-sentry.dll
  Generating native code
  hello-sentry -> /tmp/0xsgwocv.qfm/bin/Release/net9.0/linux-x64/publish/

Workload updates are available. Run `dotnet workload list` for more information.
  Debug: Logging enabled with ConsoleDiagnosticLogger and min level: Debug
Warning: Sentry option 'Debug' is set to true while Environment is production. Be aware this can cause performance degradation and is not advised. See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger for more information
  Debug: DSN read from options: https://[email protected]/42
  Debug: This looks like a Native AOT application build.
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'sentry-native' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
sentry-native.so: cannot open shared object file: No such file or directory
libsentry-native.so: cannot open shared object file: No such file or directory
sentry-native: cannot open shared object file: No such file or directory
libsentry-native: cannot open shared object file: No such file or directory

   at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
   at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x139
   at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
   at Sentry.Native.C.sentry_options_new() + 0x1f
   at Sentry.Native.C.Init(SentryOptions) + 0x22
   at Sentry.SentrySdk.InitNativeSdk(SentryOptions) + 0x2d
   at Sentry.SentrySdk.InitHub(SentryOptions) + 0x1[90](https://github.com/getsentry/sentry-dotnet/actions/runs/15779751203/job/44482314804#step:24:94)
   at Sentry.SentrySdk.Init(Action`1) + 0x3a
   at Program.<Main>$(String[] args) + 0x51
Error: [-] Aot 28.16s (28.13s|29ms)
Message
  Determining projects to restore...
  All projects are up-to-date for restore.
  hello-sentry -> /tmp/0xsgwocv.qfm/bin/Release/net9.0/linux-x64/hello-sentry.dll
  hello-sentry -> /tmp/0xsgwocv.qfm/bin/Release/net9.0/linux-x64/publish/
  Building image 'hello-sentry' with tags 'latest' on top of base image 'mcr.microsoft.com/dotnet/nightly/runtime-deps:9.0-noble-chiseled-aot'.
  Pushed image 'hello-sentry:latest' to local registry via 'docker'.

Workload updates are available. Run `dotnet workload list` for more information.
  Debug: Logging enabled with ConsoleDiagnosticLogger and min level: Debug
Warning: Sentry option 'Debug' is set to true while Environment is production. Be aware this can cause performance degradation and is not advised. See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger for more information
  Debug: DSN read from options: https://[email protected]/42
  Debug: This looks like a Native AOT application build.
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'sentry-native' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
sentry-native.so: cannot open shared object file: No such file or directory
libsentry-native.so: cannot open shared object file: No such file or directory
sentry-native: cannot open shared object file: No such file or directory
libsentry-native: cannot open shared object file: No such file or directory

   at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x46
   at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x139
   at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
   at Sentry.Native.C.sentry_options_new() + 0x1f
   at Sentry.Native.C.Init(SentryOptions) + 0x22
   at Sentry.SentrySdk.InitNativeSdk(SentryOptions) + 0x2d
   at Sentry.SentrySdk.InitHub(SentryOptions) + 0x190
   at Sentry.SentrySdk.Init(Action`1) + 0x3a
   at Program.<Main>$(String[] args) + 0x51
Error: [-] Container 10.33s (10.33s|1ms)

https://github.com/getsentry/sentry-dotnet/actions/runs/15779751203/job/44482314804

windows-latest (win-x64)
Describing Publish
  Determining projects to restore...
  Restored C:\Users\runneradmin\AppData\Local\Temp\s4hlsiu4.2qj\hello-sentry.csproj (in 6.41 sec).
  hello-sentry -> C:\Users\runneradmin\AppData\Local\Temp\s4hlsiu4.2qj\bin\Release\net9.0\win-x64\hello-sentry.dll
  Generating native code
  hello-sentry -> C:\Users\runneradmin\AppData\Local\Temp\s4hlsiu4.2qj\bin\Release\net9.0\win-x64\publish\

Workload updates are available. Run `dotnet workload list` for more information.
  Debug: Logging enabled with ConsoleDiagnosticLogger and min level: Debug
Warning: Sentry option 'Debug' is set to true while Environment is production. Be aware this can cause performance degradation and is not advised. See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger for more information
  Debug: DSN read from options: https://[email protected]/42
  Debug: This looks like a Native AOT application build.
Unhandled exception. System.DllNotFoundException: Unable to load DLL 'sentry-native' or one of its dependencies: The specified module could not be found.
   at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x50
   at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x10e
   at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x2f
   at Sentry.Native.C.sentry_options_new() + 0x24
   at Sentry.Native.C.Init(SentryOptions) + 0x25
   at Sentry.SentrySdk.InitNativeSdk(SentryOptions) + 0x2b
   at Sentry.SentrySdk.InitHub(SentryOptions) + 0x199
   at Sentry.SentrySdk.Init(Action`1) + 0x37
   at Program.<Main>$(String[] args) + 0x4e
Error: [-] Aot 30.33s (30.29s|33ms)
Message
  [!] Container 2ms (0ms|2ms)

https://github.com/getsentry/sentry-dotnet/actions/runs/15779751203/job/44482314808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sentry 5.11 causes DllNotFoundException in Native AoT application

5 participants