getsentry / sentry-dotnet

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

Getting start-up exception: System.TypeLoadException: Could not load type 'Sentry.SentryOptionsExtensions #3285

Closed JSkimming closed 1 month ago

JSkimming commented 1 month ago

Package

Sentry

.NET Flavor

.NET Core

.NET Version

8.0.4

OS

Linux

SDK Version

4.3.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

The only place I've successfully reproduced it is when deployed to our Cloud Run instance in GCP, it happens upon application startup.

Expected Result

I expect the app to start successfully and send errors and tracing to Sentry.

Actual Result

I receive the following exception on start-up.

System.TypeLoadException: Could not load type 'Sentry.SentryOptionsExtensions' from assembly 'Sentry, Version=4.3.0.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0'.
   at Microsoft.AspNetCore.Builder.ApplicationBuilderExtensions.UseSentry(IApplicationBuilder app)
   at Sentry.AspNetCore.SentryStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder e)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)
   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at <redacted>.Main(String[] args) in /<redacted>/Program.cs:line 89
JSkimming commented 1 month ago

The issue was picked up last night when @dependabot updated the following two packages:

The CI passes successfully (I guess because we don't enable Sentry on CI builds). I'm still debugging locally but have been unable to reproduce thus far.

My guess is that I have another dependency that references an earlier version of Sentry. I'm still tracking it down.

Ultimately, though, v4.3.0 via #3195 introduced a breaking change, and you have only bumped the minor version.

Assuming you are following Semantic versioning, this type of change, a breaking change to a public API requiring a recompile of dependent assemblies, warrants a major version bump. Something I suspect was not the intended consequence of what was described as a chore change in the pull request (#3195).

JSkimming commented 1 month ago

OK, I've found the issue. The problem occurred because the Sentry.Serilog update was deployed before Sentry.AspNetCore (our CI/CD deployment to a development environment is automatic). However, my point about the Major version bump is still valid, and the same issue could occur with a third-party NuGet package that references an earlier version.

For us, the problem is resolved, so I'm closing this issue.

bitsandfoxes commented 3 weeks ago

I'm glad to see this worked out for you. Sorry about that, introducing breaking changes was not our intention. But if understand correctly, this would also have been an issue if we had introduced a new API since this is down to different parts being updated at different times?