dotnet/orleans · error · ArgumentException
The configured data source creates connections of type '{act
Error message
The configured data source creates connections of type '{actualType.FullName}', but invariant '{invariantName}' uses '{expectedType.FullName}'. What it means
Thrown by DbConnectionFactory.ValidateDataSource when the DbDataSource supplied to the options creates connections whose .NET type is not assignable to the connection type produced by the provider factory registered for the invariant. Orleans requires the data source and the invariant to agree on connection type so all generated SQL and parameter handling remain valid.
Source
Thrown at src/AdoNet/Shared/Storage/DbConnectionFactory.cs:140
connection.ConnectionString = connectionString;
return connection;
}
public static void ValidateDataSource(string invariantName, DbDataSource dataSource)
{
ArgumentNullException.ThrowIfNull(dataSource);
var factory = factoryCache.GetOrAdd(invariantName, GetFactory).Factory;
using var expectedConnection = factory.CreateConnection()
?? throw new InvalidOperationException($"Database provider factory: '{invariantName}' did not return a connection object.");
using var actualConnection = dataSource.CreateConnection();
var expectedType = expectedConnection.GetType();
var actualType = actualConnection.GetType();
if (!expectedType.IsAssignableFrom(actualType))
{
throw new ArgumentException(
$"The configured data source creates connections of type '{actualType.FullName}', but invariant '{invariantName}' uses '{expectedType.FullName}'.",
nameof(dataSource));
}
}
private class CachedFactory
{
public CachedFactory(DbProviderFactory factory, string factoryName, string factoryDescription, string factoryAssemblyQualifiedNameKey)
{
Factory = factory;
FactoryName = factoryName;
FactoryDescription = factoryDescription;
FactoryAssemblyQualifiedNameKey = factoryAssemblyQualifiedNameKey;
}
/// <summary>
/// The factory to provide vendor specific functionality.
/// </summary>View on GitHub (pinned to fca799fa70)
Solutions
- Make the invariant and the DbDataSource come from the same connector (e.g. invariant 'Npgsql' with NpgsqlDataSource).
- If you intentionally changed connectors, update both AdoNetStreamOptions.Invariant and the DbDataSource construction to match.
- Drop the DataSource and use ConnectionString only if you cannot align the two.
Example fix
// before options.Invariant = AdoNetInvariants.InvariantNameSqlServer; options.DataSource = new NpgsqlDataSourceBuilder(cs).Build(); // mismatch // after options.Invariant = AdoNetInvariants.InvariantNamePostgreSql; options.DataSource = new NpgsqlDataSourceBuilder(cs).Build();
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the data source and invariant agree before startup.
var probe = dataSource.CreateConnection();
var expected = DbConnectionFactory.CreateConnection(invariant, "stub").GetType();
if (!expected.IsAssignableFrom(probe.GetType()))
throw new InvalidOperationException($"DataSource produces {probe.GetType().FullName}, invariant {invariant} expects {expected.FullName}."); Prevention
- Construct the DbDataSource with the same connector library referenced by the invariant.
- Centralize provider selection so invariant and data source cannot drift.
- Add a startup self-test that opens a connection through the configured data source.
When it happens
Trigger: Calling DbConnectionFactory.ValidateDataSource(invariantName, dataSource) where invariantName maps to one provider (e.g. 'Npgsql') but dataSource is a DbDataSource from a different provider (e.g. Microsoft.Data.SqlClient.SqlConnectionDataSource). The expectedType.IsAssignableFrom(actualType) check fails and an ArgumentException is thrown with paramName 'dataSource'.
Common situations: Mixing providers: invariant set to PostgreSQL but the DbDataSource built from SQL Server's data source builder (or vice versa); copy-pasting a data source from another service that uses a different connector; upgrading one package but not the other.
Related errors
- Database provider factory with '{invariantName}' invariant n
- Value cannot be null. (Parameter 'invariantName')
- Value cannot be null. (Parameter 'connectionString')
- 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/f4a2c70d6a81b0c6.
Report an issue: GitHub.