getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
590 stars 206 forks source link

.NET 9 Support #3484

Closed atomsk-0 closed 3 days ago

atomsk-0 commented 3 months ago

Package

Sentry

.NET Flavor

.NET

.NET Version

9.0.100-preview.6.24328.19

OS

Windows

SDK Version

4.9.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. add <PublishAot>true</PublishAot> to csproj
  2. run dotnet publish -c Release -r win-x64
  3. try run program

Expected Result

Program starting up normally

Actual Result

Throws this exception when trying to init sentry sdk. (Works normally without PublishAot flag enabled

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() + 0x32
   at Sentry.Native.C.Init(SentryOptions) + 0x2c
   at Sentry.SentrySdk.InitNativeSdk(SentryOptions) + 0x2b
   at Sentry.SentrySdk.InitHub(SentryOptions) + 0x1d2
   at Sentry.SentrySdk.Init(Action`1) + 0x37
   at Sensum.Utils.SentryClient.Setup() + 0x4e
   at Sensum.Program.Main(String[] args) + 0x16c
bitsandfoxes commented 3 months ago

Hey @atomsk-0, sorry to see you run into troubles. I wonder if this is related to some changes in .NET 9.

atomsk-0 commented 3 months ago

ye could be, seems to work fine in .NET 8 project published with NativeAot enabled

bitsandfoxes commented 3 months ago

Thanks for confirming! I guess it's time to check out the .NET 9 preview!

bruno-garcia commented 3 months ago

Also thanks for trying .NET 9 preview and reporting bugs to Sentry!! this is huge help

andrewmd5 commented 3 months ago

I'm experiencing this issue even with .NET 8 - does anyone have recommendations for a workaround? I'm cross-compiling to x64 from ARM64

EDIT: I just built Sentry native myself and dropped the DLL and crashpad into my publish folder and it seems to work.

bitsandfoxes commented 3 months ago

I'm experiencing this issue even with .NET 8

That's not great. Could you share your setup or maybe even a minimal repro for us to take a look at?

I know that we're having some trouble cross-compiling sentry-native to ARM64 but I wasn't aware that there was also an issue going the other way around.

andrewmd5 commented 3 months ago

I'm experiencing this issue even with .NET 8

That's not great. Could you share your setup or maybe even a minimal repro for us to take a look at?

I know that we're having some trouble cross-compiling sentry-native to ARM64 but I wasn't aware that there was also an issue going the other way around.

My setup is:

That is pretty much it. On any app, even .NET 8, running dotnet publish -c Release -r win-x64 yields a successful build of the app, but sentry-native can't be found at runtime and the output directory does not contain any sentry artifacts. If I build sentry-native myself and place the DLL and its associated artifacts in the output directory, the application runs.

jamescrosswell commented 3 months ago

We currently have quite a few things in the transitive build process which are "locked" to net8.0 and won't work with net9.0 and later... eg. https://github.com/getsentry/sentry-dotnet/blob/61f90d663052feb1f1becd99eb44ad0e3892f27b/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets#L9-L15

Note the $(TargetFramework.StartsWith('net8')) condition.

@andrewmd5 do you get the same result if you try to specify net8.0 explicitly when running dotnet publish?

dotnet publish -c Release -r win-x64 -f net8.0
andrewmd5 commented 3 months ago

We currently have quite a few things in the transitive build process which are "locked" to net8.0 and won't work with net9.0 and later... eg.

sentry-dotnet/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets

Lines 9 to 15 in 61f90d6

Note the `$(TargetFramework.StartsWith('net8'))` condition. [@andrewmd5](https://github.com/andrewmd5) do you get the same result if you try to specify net8.0 explicitly when running dotnet publish? dotnet publish -c Release -r win-x64 -f net8.0

Thanks for sharing that file, I suspected it might be the source of the problem, and on a second look it was. I submitted a PR.

https://github.com/getsentry/sentry-dotnet/pull/3511

jamescrosswell commented 3 months ago

Thanks for sharing that file, I suspected it might be the source of the problem, and on a second look it was. I submitted a PR.

#3511

Big 🙏 thank you for the PR @andrewmd5 - It's not quite the issue I'd thought it was!

I think we'll need to modify the same file to add support for .NET 9 as well but we can do that in a separate PR as I think that is a separate issue to the one addressed in your contribution.

andrewmd5 commented 3 months ago

My pleasure. I did a quick test and modified the targets to accept NET8+ and it seemed to work fine.

bruno-garcia commented 1 month ago

Is there a task list for .NET 9?

This got resolved and should land soon:

bitsandfoxes commented 1 month ago

Is there a task list for .NET 9?

@jamescrosswell updated the description of #3513 to stay up to date with the currently open tasks.

jamescrosswell commented 3 days ago

net9.0 support will be included in version 5 of the SDK.