{"record":{"id":"2a9162ab85f02bf5","repo":"dotnet/orleans","slug":"invalid-nameof-adonetgraindirectoryoptions-valu-2a9162","errorCode":null,"errorMessage":"Invalid {nameof(AdoNetGrainDirectoryOptions)} values for {nameof(AdoNetGrainDirectory)}|{name}. Configure exactly one of {nameof(options.ConnectionString)} or {nameof(options.DataSource)}.","messagePattern":"Invalid (.+?) values for (.+?)\\|(.+?)\\. Configure exactly one of (.+?) or (.+?)\\.","errorType":"validation","errorClass":"OrleansConfigurationException","httpStatus":null,"severity":"error","filePath":"src/AdoNet/Orleans.GrainDirectory.AdoNet/Options/AdoNetGrainDirectoryOptionsValidator.cs","lineNumber":25,"sourceCode":"/// </summary>\npublic class AdoNetGrainDirectoryOptionsValidator(AdoNetGrainDirectoryOptions options, string name) : IConfigurationValidator\n{\n    /// <inheritdoc />\n    public void ValidateConfiguration()\n    {\n        if (options is null)\n        {\n            throw new OrleansConfigurationException($\"Invalid {nameof(AdoNetGrainDirectoryOptions)} values for {nameof(AdoNetGrainDirectory)}|{name}. {nameof(options)} is required.\");\n        }\n\n        if (IsNullOrWhiteSpace(options.Invariant))\n        {\n            throw new OrleansConfigurationException($\"Invalid {nameof(AdoNetGrainDirectoryOptions)} values for {nameof(AdoNetGrainDirectory)}|{name}. {nameof(options.Invariant)} is required.\");\n        }\n\n        if (IsNullOrWhiteSpace(options.ConnectionString) == (options.DataSource is null))\n        {\n            throw new OrleansConfigurationException($\"Invalid {nameof(AdoNetGrainDirectoryOptions)} values for {nameof(AdoNetGrainDirectory)}|{name}. Configure exactly one of {nameof(options.ConnectionString)} or {nameof(options.DataSource)}.\");\n        }\n    }\n}\n","sourceCodeStart":7,"sourceCodeEnd":29,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/AdoNet/Orleans.GrainDirectory.AdoNet/Options/AdoNetGrainDirectoryOptionsValidator.cs#L7-L29","documentation":"Thrown by the ADO.NET grain directory options validator when both ConnectionString and DataSource are set, or neither is. The grain directory requires exactly one connection source. The boolean equality check fires for both the all-unset and both-set cases.","triggerScenarios":"ValidateConfiguration() runs on AdoNetGrainDirectoryOptions where IsNullOrWhiteSpace(ConnectionString) equals (DataSource is null). Happens when only Invariant is configured, or when a DataSource and a ConnectionString are both provided.","commonSituations":"Configuring Invariant but forgetting the connection; supplying ConnectionString while also injecting a DbDataSource for pooling; migration mid-flight leaving both populated.","solutions":["Provide exactly one of options.ConnectionString or options.DataSource.","Remove the redundant value if you migrated from one to the other.","Ensure the appsettings.json grain-directory section has a ConnectionString and no DataSource (or the reverse)."],"exampleFix":"// before\nbuilder.AddAdoNetGrainDirectory(\"dir\", o =>\n{\n    o.Invariant = AdoNetInvariants.InvariantNameSqlServer;\n    o.ConnectionString = \"\"; // blank, DataSource null -> error\n});\n\n// after\nbuilder.AddAdoNetGrainDirectory(\"dir\", o =>\n{\n    o.Invariant = AdoNetInvariants.InvariantNameSqlServer;\n    o.ConnectionString = \"Server=.;Database=Orleans;Trusted_Connection=True;\";\n});","handlingStrategy":"validation","validationCode":"static void CheckGrainDirectoryConnection(AdoNetGrainDirectoryOptions o)\n{\n    var exactlyOne = string.IsNullOrWhiteSpace(o.ConnectionString) != (o.DataSource is null);\n    if (!exactlyOne)\n        throw new InvalidOperationException(\"Set exactly one of ConnectionString or DataSource for the grain directory.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use one connection strategy per subsystem and document it.","Add a startup assertion for exactly-one connection source.","During ConnectionString-to-DataSource migration, remove the old field atomically."],"tags":["configuration","adonet","grain-directory","connection-string","startup-validation"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}