diff --git a/sentry-dotnet/4902/Program.cs b/sentry-dotnet/4902/Program.cs new file mode 100644 index 0000000..2442e45 --- /dev/null +++ b/sentry-dotnet/4902/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Configure Sentry as described in the issue +builder.WebHost.UseSentry(o => +{ + //o.TracesSampleRate = 1.0; + // Add any other configuration options + o.TracesSampler = context => + { + return 1.0; + }; + o.SetBeforeSend((@event, hint) => + { + // Never report server names + Console.WriteLine(@event.User.Id); + return @event; + }); + o.Debug = true; +}); + +var app = builder.Build(); + +app.MapGet("/", () => "Hello World!"); + +app.Run(); diff --git a/sentry-dotnet/4902/README.md b/sentry-dotnet/4902/README.md new file mode 100644 index 0000000..0d01c24 --- /dev/null +++ b/sentry-dotnet/4902/README.md @@ -0,0 +1,70 @@ +# Reproduction for sentry-dotnet#4902 + +**Issue:** https://github.com/getsentry/sentry-dotnet/issues/4902 + +## Description + +When upgrading from Sentry.AspNetCore SDK v5.16.2 to v6.0.0, a `TypeLoadException` occurs during application startup: + +``` +System.TypeLoadException: Could not load type 'BindableSentryExperimentalOptions' from assembly 'Sentry, Version=6.0.0.0' +``` + +This error happens when the SDK tries to bind configuration from `appsettings.json` using source-generated configuration binding. + +## Steps to Reproduce + +1. Install dependencies: + ```bash + dotnet restore + ``` + +2. Run the application: + ```bash + dotnet run + ``` + +## Expected Behavior + +The ASP.NET Core application should start successfully with Sentry SDK v6.0.0 configured, just as it did with v5.16.2. + +## Actual Behavior + +The application crashes during startup with: + +``` +Unhandled exception. System.TypeLoadException: Could not load type 'BindableSentryExperimentalOptions' from assembly 'Sentry, Version=6.0.0.0, Culture=neutral, PublicKeyToken=[REDACTED]'. + at Microsoft.Extensions.Configuration.Binder.SourceGeneration.F69BD955067CC1B62D0915FD5271F3D3428E092A00BA3FDBE06C4BF5D97765D7A__BindingExtensions.BindCore(IConfiguration configuration, BindableSentryAspNetCoreOptions& instance, Boolean defaultValueIfNotFound, BinderOptions binderOptions) + at Microsoft.Extensions.Configuration.Binder.SourceGeneration.F69BD955067CC1B62D0915FD5271F3D3428E092A00BA3FDBE06C4BF5D97765D7A__BindingExtensions.Bind_BindableSentryAspNetCoreOptions(IConfiguration configuration, Object instance) + at Sentry.AspNetCore.SentryAspNetCoreOptionsSetup.Configure(SentryAspNetCoreOptions options) +``` + +## Workaround + +Reverting to v5.16.2 resolves the issue: +```bash +dotnet add package Sentry.AspNetCore -v 5.16.2 +``` + +## Environment + +- .NET SDK: 9.0.101 +- Sentry.AspNetCore: 6.0.0 +- OS: macOS + +## Notes + +This reproduction attempts to recreate the conditions described in the issue. The error may be environment-specific or related to build cache/AOT compilation settings. If the error doesn't reproduce immediately, try: + +1. Clean and rebuild: + ```bash + dotnet clean + rm -rf bin/ obj/ + dotnet build + ``` + +2. Check if you have any global.json or Directory.Build.props files that might affect the build + +3. The issue mentions MAUI workloads were installed - try with/without MAUI workloads installed + +The issue reporter confirmed that downgrading to v5.16.2 fixes the problem, suggesting this is a regression in v6.0.0 related to the source-generated configuration binding for `BindableSentryExperimentalOptions`. diff --git a/sentry-dotnet/4902/appsettings.json b/sentry-dotnet/4902/appsettings.json new file mode 100644 index 0000000..b406af6 --- /dev/null +++ b/sentry-dotnet/4902/appsettings.json @@ -0,0 +1,13 @@ +{ + "Sentry": { + // "Dsn": "", + "SendDefaultPii": true, + "MaxRequestBodySize": "Always", + "MinimumBreadcrumbLevel": "Debug", + "MinimumEventLevel": "Warning", + "AttachStackTrace": true, + "Debug": true, + "TracesSampleRate": 1.0 + }, + "AllowedHosts": "*" +} diff --git a/sentry-dotnet/4902/sentry-dotnet-4902.csproj b/sentry-dotnet/4902/sentry-dotnet-4902.csproj new file mode 100644 index 0000000..c8f8e13 --- /dev/null +++ b/sentry-dotnet/4902/sentry-dotnet-4902.csproj @@ -0,0 +1,15 @@ + + + + net9.0 + enable + enable + sentry_dotnet_4902 + true + + + + + + +