dotnet/orleans · error · ArgumentNullException
Value cannot be null. (Parameter 'invariantName')
Error message
Value cannot be null. (Parameter 'invariantName')
What it means
Thrown by DbConnectionFactory.CreateConnection when the invariantName argument is null, empty, or whitespace. The factory cannot resolve a DbProviderFactory without a concrete invariant, so it fails fast with an ArgumentNullException naming the 'invariantName' parameter.
Source
Thrown at src/AdoNet/Shared/Storage/DbConnectionFactory.cs:107
}
throw new AggregateException(exceptions!);
void AddException(Exception ex)
{
if (exceptions == null)
{
exceptions = new List<Exception>();
}
exceptions.Add(ex);
}
}
public static DbConnection CreateConnection(string invariantName, string connectionString)
{
if (string.IsNullOrWhiteSpace(invariantName))
{
throw new ArgumentNullException(nameof(invariantName));
}
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new ArgumentNullException(nameof(connectionString));
}
var factory = factoryCache.GetOrAdd(invariantName, GetFactory).Factory;
var connection = factory.CreateConnection();
if (connection == null)
{
throw new InvalidOperationException($"Database provider factory: '{invariantName}' did not return a connection object.");
}
connection.ConnectionString = connectionString;
return connection;
}View on GitHub (pinned to fca799fa70)
Solutions
- Ensure the invariant name is set to a non-empty supported value before the connection is created (e.g. options.Invariant = AdoNetInvariants.InvariantNamePostgreSql).
- Validate configuration at builder time; the AdoNetStreamOptionsValidator already catches a null Invariant if wired up.
- Add a null/whitespace check in your own bootstrap code to fail with a clearer message.
Example fix
// before
var conn = DbConnectionFactory.CreateConnection(options.Invariant, cs);
// options.Invariant is null
// after
if (string.IsNullOrWhiteSpace(options.Invariant))
throw new InvalidOperationException("Invariant must be set.");
var conn = DbConnectionFactory.CreateConnection(options.Invariant, cs); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(invariantName))
throw new InvalidOperationException("An ADO.NET invariant name must be provided."); Prevention
- Always set the Invariant property on the options object.
- Use the AdoNetStreamOptionsValidator (registered by default) to catch null invariants at startup.
- Bind configuration through typed options so missing values surface clearly.
When it happens
Trigger: Calling DbConnectionFactory.CreateConnection(null, connectionString), CreateConnection("", ...), or CreateConnection(" ", ...). In practice this happens when AdoNetStreamOptions.Invariant (or the equivalent on clustering/reminders/persistence options) was never set and defaults to null.
Common situations: Forgetting to set the Invariant property on the options object; reading the invariant from a configuration section that is absent; passing a variable that was conditionally assigned and ended up null.
Related errors
- Value cannot be null. (Parameter 'connectionString')
- Database provider factory with '{invariantName}' invariant n
- The configured data source creates connections of type '{act
- Not all required queries found. Missing are: {string.Join(",
- Invalid {nameof(AdoNetStreamOptions)} values for ADO.NET Str
AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13).
Data as JSON: /api/errors/4e5efdb95c909630.
Report an issue: GitHub.