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

  1. Ensure the invariant name is set to a non-empty supported value before the connection is created (e.g. options.Invariant = AdoNetInvariants.InvariantNamePostgreSql).
  2. Validate configuration at builder time; the AdoNetStreamOptionsValidator already catches a null Invariant if wired up.
  3. 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

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


AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13). Data as JSON: /api/errors/4e5efdb95c909630. Report an issue: GitHub.