{"record":{"id":"2006d0c7b281956d","repo":"dotnet/aspnetcore","slug":"cannot-have-empty-query-parameter-names","errorCode":null,"errorMessage":"Cannot have empty query parameter names.","messagePattern":"Cannot have empty query parameter names\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/NavigationManagerExtensions.cs","lineNumber":166,"sourceCode":"            _builder.Append(hash);\n        }\n    }\n\n    // A utility for feeding a collection of parameter values into a QueryStringBuilder.\n    // This is used when generating a querystring with a query parameter that has multiple values.\n    private readonly struct QueryParameterSource<TValue>\n    {\n        private readonly IEnumerator<TValue?>? _enumerator;\n        private readonly QueryParameterFormatter<TValue>? _formatter;\n\n        public string EncodedName { get; }\n\n        // Creates an empty instance to simulate a source without any elements.\n        public QueryParameterSource(string name)\n        {\n            if (string.IsNullOrEmpty(name))\n            {\n                throw new InvalidOperationException(EmptyQueryParameterNameExceptionMessage);\n            }\n\n            EncodedName = Uri.EscapeDataString(name);\n\n            _enumerator = default;\n            _formatter = default;\n        }\n\n        public QueryParameterSource(string name, IEnumerable<TValue?> values, QueryParameterFormatter<TValue> formatter)\n            : this(name)\n        {\n            _enumerator = values.GetEnumerator();\n            _formatter = formatter;\n        }\n\n        public bool TryAppendNextParameter(ref QueryStringBuilder builder)\n        {\n            if (_enumerator is null || !_enumerator.MoveNext())","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/NavigationManagerExtensions.cs#L148-L184","documentation":"Thrown by the QueryParameterSource(string name) constructor when name is null or empty. The extension API that builds query strings (GetUriWithQueryParameter[s]) refuses empty parameter names because they cannot be encoded into a well-formed query string (a '?' with no name is ambiguous). The check is shared by the single-value and multi-value parameter sources.","triggerScenarios":"Calling navigationManager.GetUriWithQueryParameter(name, value) or GetUriWithQueryParameters(dict) where name (or a dictionary key) is null, empty, or whitespace-only. Reached when a caller passes a computed name that turned out empty (e.g. derived from a missing route parameter or an unset binding).","commonSituations":"Building a query parameter name from an empty input field; a dictionary produced from a query string round-trip that contains an empty key; an unset [SupplyParameterFromQuery] property whose name defaults to empty.","solutions":["Validate that the parameter name is non-empty before calling GetUriWithQueryParameter(s); guard with if (string.IsNullOrWhiteSpace(name)).","When building the parameters dictionary, filter out empty keys before passing it to GetUriWithQueryParameters.","If the name is optional, skip the call entirely rather than passing an empty string.","Trace where the empty name originates - often an unbound form field or a null-coalesced default."],"exampleFix":"// before: name can be empty when the input is blank\nvar uri = nav.GetUriWithQueryParameter(userInput, value);\n\n// after: guard before calling\nif (!string.IsNullOrWhiteSpace(userInput))\n    uri = nav.GetUriWithQueryParameter(userInput, value);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name)) throw new InvalidOperationException(\"Query parameter name must be non-empty.\");","typeGuard":"static bool IsValidQueryName(string? name) => !string.IsNullOrWhiteSpace(name);","tryCatchPattern":"try { _ = new QueryParameterSource(name, values, formatter); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"empty query parameter names\"))\n{ /* skip or default the name */ }","preventionTips":["Filter empty keys out of any dictionary before calling GetUriWithQueryParameters.","Bind [SupplyParameterFromQuery] with an explicit Name when the property name is dynamic.","Add a guard at the form boundary: reject empty filter names before they propagate."],"tags":["blazor","querystring","validation","uri"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}