{"record":{"id":"4e5efdb95c909630","repo":"dotnet/orleans","slug":"value-cannot-be-null-parameter-invariantname","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'invariantName')","messagePattern":"Value cannot be null\\. \\(Parameter 'invariantName'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/AdoNet/Shared/Storage/DbConnectionFactory.cs","lineNumber":107,"sourceCode":"            }\n\n            throw new AggregateException(exceptions!);\n\n            void AddException(Exception ex)\n            {\n                if (exceptions == null)\n                {\n                    exceptions = new List<Exception>();\n                }\n                exceptions.Add(ex);\n            }\n        }\n\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        }","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/AdoNet/Shared/Storage/DbConnectionFactory.cs#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar conn = DbConnectionFactory.CreateConnection(options.Invariant, cs);\n// options.Invariant is null\n\n// after\nif (string.IsNullOrWhiteSpace(options.Invariant))\n    throw new InvalidOperationException(\"Invariant must be set.\");\nvar conn = DbConnectionFactory.CreateConnection(options.Invariant, cs);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(invariantName))\n    throw new InvalidOperationException(\"An ADO.NET invariant name must be provided.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["adonet","argument-null","configuration","database","orleans"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}