dotnet/orleans · error · ArgumentNullException

Value cannot be null. (Parameter 'connectionString')

Error message

Value cannot be null. (Parameter 'connectionString')

What it means

Thrown by DbConnectionFactory.CreateConnection when the connectionString argument is null, empty, or whitespace. A connection string is mandatory to open a database connection; Orleans rejects it early with an ArgumentNullException on the 'connectionString' parameter rather than letting the provider throw an opaque error.

Source

Thrown at src/AdoNet/Shared/Storage/DbConnectionFactory.cs:112

            {
                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;
        }

        public static void ValidateDataSource(string invariantName, DbDataSource dataSource)
        {
            ArgumentNullException.ThrowIfNull(dataSource);

View on GitHub (pinned to fca799fa70)

Solutions

  1. Provide a valid, non-empty connection string matching the chosen invariant's provider.
  2. Bind AdoNetStreamOptions.ConnectionString from a verified configuration source (e.g. IConfiguration.GetSection).
  3. If using DbDataSource instead, do not pass a connection string to CreateConnection; configure DataSource and use the data-source path.

Example fix

// before
options.ConnectionString = config["NotTheRightKey"]; // null
var conn = DbConnectionFactory.CreateConnection(invariant, options.ConnectionString);

// after
options.ConnectionString = config.GetConnectionString("OrleansStreamDb");
var conn = DbConnectionFactory.CreateConnection(invariant, options.ConnectionString);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(connectionString))
    throw new InvalidOperationException("A connection string (or DbDataSource) must be configured.");

Prevention

When it happens

Trigger: Calling DbConnectionFactory.CreateConnection(invariant, null), CreateConnection(invariant, ""), or CreateConnection(invariant, " "). Occurs when AdoNetStreamOptions.ConnectionString is unset and no DataSource is configured, or when a connection string is read from a missing secrets/env source.

Common situations: Forgetting to bind the connection string from configuration; the environment variable holding it is not set in the deployed environment; a typo in the config key name; using DataSource-based config but accidentally calling CreateConnection with an empty string.

Related errors


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