ASP.NET Core connection string null / not found in CI
Configuration returned no value for the connection string, so GetConnectionString("Default") was null. In CI the string usually lives in appsettings only for local dev, or is expected from an environment variable that was never set.
What this error means
The app fails with "System.ArgumentException: The ConnectionString property has not been initialized." or EF "No connection string named 'Default' was found." even though it works locally.
System.InvalidOperationException: A named connection string was used, but the name
'Default' was not found in the application's configuration.Common causes
The string is only in a local config source
The connection string lives in appsettings.Development.json or user-secrets that are not present in CI, and nothing supplies it there.
The environment variable name is wrong
The value is expected from an env var but the key does not match the ConnectionStrings:Default binding (must be ConnectionStrings__Default).
How to fix it
Provide the connection string via environment
- Set
ConnectionStrings__Defaultin the CI step env from a secret. - Confirm
GetConnectionString("Default")maps to that key (double underscore = colon). - Do not commit real connection strings; use CI secrets.
env:
ConnectionStrings__Default: Host=localhost;Database=app;Username=postgres;Password=postgresFail fast on a missing string
Read the value with a required check so a missing configuration produces a clear error at startup.
var cs = builder.Configuration.GetConnectionString("Default")
?? throw new InvalidOperationException("ConnectionStrings:Default not configured");How to prevent it
- Supply CI connection strings via ConnectionStrings__ environment variables from secrets.
- Keep local-only strings out of the config CI relies on.
- Validate required configuration at startup so gaps fail fast.