{"record":{"id":"b964e3c1ccb5f1c7","repo":"SignalR/SignalR","slug":"headers-b964e3","errorCode":null,"errorMessage":"headers","messagePattern":"headers","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.AspNet.SignalR.Client/Transports/WebSockets/WebSocketWrapperRequest.cs","lineNumber":95,"sourceCode":"        }\n\n        public string Accept\n        {\n            get\n            {\n                return null;\n            }\n            set\n            {\n\n            }\n        }\n\n        public void SetRequestHeaders(IDictionary<string, string> headers)\n        {\n            if (headers == null)\n            {\n                throw new ArgumentNullException(\"headers\");\n            }\n\n            foreach (KeyValuePair<string, string> headerEntry in headers)\n            {\n                _clientWebSocket.Options.SetRequestHeader(headerEntry.Key, headerEntry.Value);\n            }\n        }\n\n        public void AddClientCerts(X509CertificateCollection certificates)\n        {\n            if (certificates == null)\n            {\n                throw new ArgumentNullException(\"certificates\");\n            }\n\n            _clientWebSocket.Options.ClientCertificates = certificates;\n        }\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/SignalR/SignalR/blob/693053b89a9e1f5ce819e3233ed159a6409de22b/src/Microsoft.AspNet.SignalR.Client/Transports/WebSockets/WebSocketWrapperRequest.cs#L77-L113","documentation":"Thrown by WebSocketWrapperRequest.SetRequestHeaders when the headers dictionary is null. The method iterates every header entry to forward it to ClientWebSocket.Options.SetRequestHeader, so a null dictionary cannot be enumerated.","triggerScenarios":"Calling SetRequestHeaders(null) directly, or passing through a null headers collection from a request builder that produced no headers.","commonSituations":"Custom IRequest implementations delegating to WebSocketWrapperRequest, or configuration paths where headers are conditionally set and the collection stays null when omitted.","solutions":["Pass an empty Dictionary<string,string> instead of null when no custom headers are needed.","Initialize the headers collection eagerly so it is never null downstream.","Guard with a null check at the call site before delegating to SetRequestHeaders."],"exampleFix":"// before\nrequest.SetRequestHeaders(hasHeaders ? headers : null);\n\n// after\nrequest.SetRequestHeaders(headers ?? new Dictionary<string, string>());","handlingStrategy":"validation","validationCode":"var safeHeaders = headers ?? new Dictionary<string, string>();\nrequest.SetRequestHeaders(safeHeaders);","typeGuard":"if (headers is IDictionary<string,string> d && d != null) { request.SetRequestHeaders(d); }","tryCatchPattern":null,"preventionTips":["Initialize header collections eagerly to empty dictionaries.","Coalesce null collections to empty at the configuration boundary.","Treat 'no headers' as empty, not null."],"tags":["argumentnull","websocket","headers","client"],"backgroundTag":null,"analyzedSha":"693053b89a9e1f5ce819e3233ed159a6409de22b","analyzedAt":"2026-08-13T22:23:59.793Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}