You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot pass empty string as Dsn from appsettings.json when using generic host builder #3875
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 dotnet/runtime#62532 and/or dotnet/runtime#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.
In the .NET SDK version 7.0 (with #5739) we're introducing a new Sentry.Extensions.Hosting package with UseSentry specific for generic host apps. It reads the Sentry section of appsettings.json the same way Sentry.AspNetCore currently does, so "Dsn": "" disables the SDK.
Host.CreateDefaultBuilder(args).UseSentry() works the same way. The Sentry.Samples.GenericHost sample will now also use UseSentry.
One thing for the upgrade: in 7.0, Logging.AddSentry() no longer initializes the SDK (#5595), so the setup in your ConfigureLogging moves to UseSentry.
Activity
jamescrosswell commentedon Jan 9, 2025
Thanks for the sleuthing @jnoordsij. 🙏🏻
I added my 2c to the issue in the
dotnet/runtimerepo.As a workaround, you could do something like this when initialising Sentry in your generic host:
meriturva commentedon Sep 23, 2025
Here my workaround:
14 remaining items
jnoordsij commentedon Sep 10, 2026
From my initial tests on .NET v11.0.0-rc.1.26425.128, which includes dotnet/runtime@d6089ff, this indeed seems fixed.
test(hosting): cover UseSentry and the hosted service on both builders
test(hosting): cover UseSentry and the hosted service on both builders
test(hosting): cover UseSentry and the hosted service on both builders
test(hosting): cover a disabled SDK and starting hosted services in MAUI
feat: add Sentry.Extensions.Hosting with UseSentry for generic host a…
ric-oliv commentedon Oct 19, 2026
Thank you for your report (and support) here, @jnoordsij and @meriturva !
In the .NET SDK version 7.0 (with #5739) we're introducing a new
Sentry.Extensions.Hostingpackage withUseSentryspecific for generic host apps. It reads theSentrysection ofappsettings.jsonthe same waySentry.AspNetCorecurrently does, so"Dsn": ""disables the SDK.{ "Sentry": { "Dsn": "" } }Host.CreateDefaultBuilder(args).UseSentry()works the same way. TheSentry.Samples.GenericHostsample will now also useUseSentry.One thing for the upgrade: in 7.0,
Logging.AddSentry()no longer initializes the SDK (#5595), so the setup in yourConfigureLoggingmoves toUseSentry.