{"record":{"id":"e80fb1661c1afb1d","repo":"dotnet/orleans","slug":"database-provider-factory-invariantname-did-n","errorCode":null,"errorMessage":"Database provider factory: '{invariantName}' did not return a connection object.","messagePattern":"Database provider factory: '(.+?)' did not return a connection object\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/AdoNet/Shared/Storage/DbConnectionFactory.cs","lineNumber":120,"sourceCode":"\n        public static DbConnection CreateConnection(string invariantName, string connectionString)\n        {\n            if (string.IsNullOrWhiteSpace(invariantName))\n            {\n                throw new ArgumentNullException(nameof(invariantName));\n            }\n\n            if (string.IsNullOrWhiteSpace(connectionString))\n            {\n                throw new ArgumentNullException(nameof(connectionString));\n            }\n\n            var factory = factoryCache.GetOrAdd(invariantName, GetFactory).Factory;\n            var connection = factory.CreateConnection();\n\n            if (connection == null)\n            {\n                throw new InvalidOperationException($\"Database provider factory: '{invariantName}' did not return a connection object.\");\n            }\n\n            connection.ConnectionString = connectionString;\n            return connection;\n        }\n\n        public static void ValidateDataSource(string invariantName, DbDataSource dataSource)\n        {\n            ArgumentNullException.ThrowIfNull(dataSource);\n\n            var factory = factoryCache.GetOrAdd(invariantName, GetFactory).Factory;\n            using var expectedConnection = factory.CreateConnection()\n                ?? throw new InvalidOperationException($\"Database provider factory: '{invariantName}' did not return a connection object.\");\n            using var actualConnection = dataSource.CreateConnection();\n\n            var expectedType = expectedConnection.GetType();\n            var actualType = actualConnection.GetType();\n            if (!expectedType.IsAssignableFrom(actualType))","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/AdoNet/Shared/Storage/DbConnectionFactory.cs#L102-L138","documentation":"Thrown by DbConnectionFactory.CreateConnection when the resolved DbProviderFactory.CreateConnection() returns null. Under normal circumstances a registered provider factory always returns a connection instance; a null return indicates the connector assembly loaded but its factory is broken, misconfigured, or partially initialized.","triggerScenarios":"The invariant resolved successfully (so error 121 did not fire) and the assembly loaded, but factory.CreateConnection() yielded null. This is rare and points to a defective or unsupported version of the ADO.NET connector, or a factory singleton that has been corrupted.","commonSituations":"Using an outdated or preview version of a connector whose CreateConnection is known to return null; a connector that requires additional registration (e.g. SQLite native dependencies not present) leaving the factory in a degraded state; reflection retrieved a non-standard Instance field.","solutions":["Upgrade the ADO.NET connector package (e.g. Microsoft.Data.SqlClient, Npgsql, MySqlConnector) to a stable, supported version.","Verify the connector's native dependencies are present in the runtime environment.","If the problem persists, open an issue with the connector vendor, since CreateConnection should never return null."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var conn = DbConnectionFactory.CreateConnection(invariant, cs); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"did not return a connection\"))\n{\n    // log and surface a connector-package/dependency problem\n    throw new InvalidOperationException($\"Connector '{invariant}' failed to produce a connection. Verify the package and native deps.\", ex);\n}","preventionTips":["Pin connector packages to stable, tested versions in your .csproj.","Include connector integration tests in CI that actually open a connection.","Verify native dependencies (e.g. SQLite native binaries) are present in the deployment image."],"tags":["adonet","database","provider-factory","connector","orleans"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}