getsentry/sentry-dotnet

.NET 9 Support

Closed this issue · 15 comments

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

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

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

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

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

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.

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.

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:

  • Windows 11 (ARM64) running inside a VM on my MacBook
  • .NET 8 and .NET 9 (RC) installed side-by-side

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.

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.

<Project>
<ItemGroup Condition="$(TargetFramework.StartsWith('net8')) and '$(OutputType)' == 'Exe' And '$(RuntimeIdentifier)' == 'win-x64'">
<DirectPInvoke Include="sentry-native" />
<NativeLibrary Include="$(MSBuildThisFileDirectory)..\sentry-native\win-x64\sentry-native.lib" />
<NativeLibrary Include="dbghelp.lib" />
<NativeLibrary Include="winhttp.lib" />
</ItemGroup>

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

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 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.

#3511

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.

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

Is there a task list for .NET 9?

This got resolved and should land soon:

Is there a task list for .NET 9?

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

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

For those who caught in this, the workaround for now is to link it manually on your main publish app

<!-- Region: Sentry -->
<DirectPInvoke Include="sentry-native" />
<NativeLibrary Include="$(NugetPackageRoot)\sentry\4.13.0\sentry-native\win-x64\sentry-native.lib" />
<NativeLibrary Include="dbghelp.lib" />
<NativeLibrary Include="winhttp.lib" />