{"record":{"id":"97ab678c57119a5d","repo":"reactiveui/refit","slug":"only-one-parameter-can-be-a-headercollection-param","errorCode":null,"errorMessage":"Only one parameter can be a HeaderCollection parameter","messagePattern":"Only one parameter can be a HeaderCollection parameter","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Refit.Reflection/RestMethodInfoInternal.AttributeReading.cs","lineNumber":136,"sourceCode":"        for (var i = 0; i < parameterArray.Length; i++)\n        {\n            if (sets[i].HeaderCollection is null)\n            {\n                continue;\n            }\n\n            // Opted for IDictionary<string, string> semantics here as opposed to the looser\n            // IEnumerable<KeyValuePair<string, string>> because IDictionary enforces unique keys.\n            if (!parameterArray[i].ParameterType.IsAssignableFrom(typeof(IDictionary<string, string>)))\n            {\n                throw new ArgumentException(\n                    $\"HeaderCollection parameter of type {parameterArray[i].ParameterType.Name} is not assignable from IDictionary<string, string>\");\n            }\n\n            // Throw if there is already a HeaderCollection parameter.\n            if (headerIndex >= 0)\n            {\n                throw new ArgumentException(\"Only one parameter can be a HeaderCollection parameter\");\n            }\n\n            headerIndex = i;\n        }\n\n        return headerIndex;\n    }\n\n    /// <summary>Builds the map of parameter indexes to request property keys.</summary>\n    /// <param name=\"parameterArray\">The array of method parameters.</param>\n    /// <param name=\"sets\">The classified attribute set for each parameter.</param>\n    /// <returns>A map of parameter indexes to property keys.</returns>\n    internal static Dictionary<int, string> BuildRequestPropertyMap(ParameterInfo[] parameterArray, ParameterAttributeSet[] sets)\n    {\n        Dictionary<int, string>? propertyMap = null;\n\n        for (var i = 0; i < parameterArray.Length; i++)\n        {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.Reflection/RestMethodInfoInternal.AttributeReading.cs#L118-L154","documentation":"Refit permits at most one header-collection parameter per method because it needs a single target to assign the header dictionary to. The loop tracks the first header-collection index and throws if it finds a second one.","triggerScenarios":"Two (or more) parameters on the same Refit interface method are both bound as header collections.","commonSituations":"Copy-pasting a header parameter into a second argument; combining an inherited header-collection param with a new one; refactor merging header params.","solutions":["Merge multiple header-collection parameters into a single IDictionary<string,string>.","If you need individual headers, use single [Header(\"name\")] string parameters instead of a second collection."],"exampleFix":"// before\n[Get(\"/x\")] Task GetAsync([HeaderCollection] IDictionary<string,string> a,\n                        [HeaderCollection] IDictionary<string,string> b);\n\n// after\n[Get(\"/x\")] Task GetAsync([HeaderCollection] IDictionary<string,string> all);\n// caller merges: all = new[] { a, b }.SelectMany(d => d).ToDictionary(...)","handlingStrategy":"validation","validationCode":"static void AssertSingleHeaderCollection(MethodInfo m) {\n    var count = m.GetParameters().Count(p => /* has header-collection attribute */ false);\n    if (count > 1) throw new InvalidOperationException(\"Multiple header-collection params on \" + m.Name);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allow only one header-collection parameter per method.","Merge multiple header dictionaries before the call.","Use individual [Header] params for specific headers."],"tags":["refit","headers","attributes","design-time"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}