getsentry / getsentry/sentry-dotnet
Cannot pass empty string as Dsn from appsettings.json when using generic host builder
- Dominant language
- C#
- Stars
- 770
- Forks
- 248
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 49
Description
### Package
Sentry
### .NET Flavor
.NET
### .NET Version
9.0.0
### OS
Android
### SDK Version
9.0.101
### Self-Hosted Sentry Version
_No response_
### Steps to Reproduce
Run the `Sentry.Samples.GenericHost` project with `"Dsn": ""` set in `appsettings.json`
### Expected Result
The application to run with Sentry SDK disabled
### Actual Result
System.ArgumentNullException: 'Value cannot be null. (Parameter 'You must supply a DSN to use Sentry.To disable Sentry, pass an empty string: "".See https://docs.sentry.io/platforms/dotnet/configuration/options/#dsn')'
### Further details
This seems to affect only setups with generic host builder; with web host setting an empty string in `appsettings.json` works just fine.
In my setup the call is located within a `IHostBuilder.ConfigureLogging`, which suffers from this issue as it is similar to the sample above and thus most likely caused by same underlying reason.
My own research showed that https://github.com/dotnet/runtime/issues/62532 and/or https://github.com/dotnet/runtime/issues/65594 might be the root cause of this issue, as the .NET runtime seems to cast empty strings to null in some particular situations. If possible, it would be nice to have a way to prevent this from happening within the scope of the Sentry SDK.
### Workaround
When manually setting the DSN with e.g.
```csharp
builder.Logging.AddSentry((sentryOptions) =>
{
sentryOptions.Dsn = builder.Configuration["Sentry:Dsn"];
});
```
the problem does not occur.
Contributor guide
Assessment
This issue has not been assessed yet.