Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions sentry-dotnet/4902/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
70 changes: 70 additions & 0 deletions sentry-dotnet/4902/README.md
Original file line number Diff line number Diff line change
@@ -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.<BindingExtensions_g>F69BD955067CC1B62D0915FD5271F3D3428E092A00BA3FDBE06C4BF5D97765D7A__BindingExtensions.BindCore(IConfiguration configuration, BindableSentryAspNetCoreOptions& instance, Boolean defaultValueIfNotFound, BinderOptions binderOptions)
at Microsoft.Extensions.Configuration.Binder.SourceGeneration.<BindingExtensions_g>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`.
13 changes: 13 additions & 0 deletions sentry-dotnet/4902/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Sentry": {
// "Dsn": "",
"SendDefaultPii": true,
"MaxRequestBodySize": "Always",
"MinimumBreadcrumbLevel": "Debug",
"MinimumEventLevel": "Warning",
"AttachStackTrace": true,
"Debug": true,
"TracesSampleRate": 1.0
},
"AllowedHosts": "*"
}
15 changes: 15 additions & 0 deletions sentry-dotnet/4902/sentry-dotnet-4902.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>sentry_dotnet_4902</RootNamespace>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Sentry.AspNetCore" Version="6.0.0" />
</ItemGroup>

</Project>