{"record":{"id":"77f99ba24dd24fbf","repo":"dotnet/orleans","slug":"value-cannot-be-null-parameter-query","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'query')","messagePattern":"Value cannot be null\\. \\(Parameter 'query'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/AdoNet/Shared/Storage/RelationalStorage.cs","lineNumber":197,"sourceCode":"        ///     //marked with by convention by underscore (_).\n        /// }, (selector, resultSetCount) =>\n        ///    {\n        ///        //This function is called once for each row returned, so the final result will be an\n        ///        //IEnumerable&lt;Information&gt;.\n        ///        return new Information\n        ///        {\n        ///            TABLE_CATALOG = selector.GetValueOrDefault&lt;string&gt;(\"TABLE_CATALOG\"),\n        ///            TABLE_NAME = selector.GetValueOrDefault&lt;string&gt;(\"TABLE_NAME\")\n        ///        }\n        ///}).ConfigureAwait(continueOnCapturedContext: false);\n        /// </code>\n        /// </example>\n        public async Task<IEnumerable<TResult>> ReadAsync<TResult>(string query, Action<IDbCommand>? parameterProvider, Func<IDataRecord, int, CancellationToken, Task<TResult>> selector, CommandBehavior commandBehavior = CommandBehavior.Default, CancellationToken cancellationToken = default)\n        {\n            //If the query is something else that is not acceptable (e.g. an empty string), there will an appropriate database exception.\n            if (query == null)\n            {\n                throw new ArgumentNullException(nameof(query));\n            }\n\n            if (selector == null)\n            {\n                throw new ArgumentNullException(nameof(selector));\n            }\n\n            return (await ExecuteAsync(query, parameterProvider, ExecuteReaderAsync, selector, commandBehavior, cancellationToken).ConfigureAwait(false)).Item1;\n        }\n\n\n        /// <summary>\n        /// Executes a given statement. Especially intended to use with <em>INSERT</em>, <em>UPDATE</em>, <em>DELETE</em> or <em>DDL</em> queries.\n        /// </summary>\n        /// <param name=\"query\">The query to execute.</param>\n        /// <param name=\"parameterProvider\">Adds parameters to the query. Parameter names must match those defined in the query.</param>\n        /// <param name=\"commandBehavior\">The command behavior that should be used. Defaults to <see cref=\"CommandBehavior.Default\"/>.</param>\n        /// <param name=\"cancellationToken\">The cancellation token. Defaults to <see cref=\"CancellationToken.None\"/>.</param>","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/AdoNet/Shared/Storage/RelationalStorage.cs#L179-L215","documentation":"Thrown by RelationalStorage.ReadAsync<TResult>(string query, ...) when query is null. The method deliberately allows empty strings (the database will surface its own error) but rejects null outright with ArgumentNullException(nameof(query)). The selector, not the query text, is the only other hard prerequisite.","triggerScenarios":"Calling storage.ReadAsync<TResult>(null, parameterProvider, selector, ...) where the query string was not supplied, e.g. a query-builder returned null or a field was not loaded from a script file.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-null SQL string; build queries with a builder that never returns null (use string.Empty to let the DB reject it, or validate first).","Load SQL scripts defensively: var sql = await File.ReadAllTextAsync(path); and check for null/empty before calling ReadAsync.","Coalesce nulls: query ?? throw new ArgumentNullException(nameof(query)).","Unit-test query providers to guarantee non-null output."],"exampleFix":"// before\nvar rows = await storage.ReadAsync<T>(queryOrNull, p, selector);\n\n// after\nif (queryOrNull is null) throw new InvalidOperationException(\"Query not loaded.\");\nvar rows = await storage.ReadAsync<T>(queryOrNull, p, selector);","handlingStrategy":"validation","validationCode":"if (query is null) throw new ArgumentNullException(nameof(query));","typeGuard":"static bool HasQuery(string? q) => q is not null;","tryCatchPattern":"try { await storage.ReadAsync<T>(query, p, selector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == nameof(query)) { /* load script */ }","preventionTips":["Load SQL scripts at startup and assert non-null.","Enable nullable reference types so null queries are compile-time warnings.","Use a query-builder that never returns null."],"tags":["csharp","dotnet","orleans","adonet","argument-validation"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}