{"record":{"id":"964faf32c476156e","repo":"reactiveui/refit","slug":"headercollection-parameter-of-type-parameterarray","errorCode":null,"errorMessage":"HeaderCollection parameter of type {parameterArray[i].ParameterType.Name} is not assignable from IDictionary<string, string>","messagePattern":"HeaderCollection parameter of type (.+?) is not assignable from IDictionary<string, string>","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Refit.Reflection/RestMethodInfoInternal.AttributeReading.cs","lineNumber":129,"sourceCode":"    /// <exception cref=\"ArgumentException\">A header collection parameter is not assignable from\n    /// <c>IDictionary&lt;string, string&gt;</c>, or more than one parameter carries\n    /// <see cref=\"HeaderCollectionAttribute\"/>.</exception>\n    internal static int GetHeaderCollectionParameterIndex(ParameterInfo[] parameterArray, ParameterAttributeSet[] sets)\n    {\n        var headerIndex = -1;\n\n        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>","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.Reflection/RestMethodInfoInternal.AttributeReading.cs#L111-L147","documentation":"A parameter marked as a header collection must accept IDictionary<string,string>, because Refit assigns header collections via that interface (the comment notes IDictionary is chosen to enforce unique keys). If the parameter type is not assignable from IDictionary<string,string> (e.g. a List, an array, a custom type without that interface), this throws.","triggerScenarios":"Declaring a header-collection parameter (a parameter bound to multiple headers) whose declared type does not implement/accept IDictionary<string,string>, such as IEnumerable, a List<>, a record, or a Dictionary with non-string keys.","commonSituations":"Binding headers to a Dictionary<string,string[]> or a custom multi-value type; using a collection type Refit cannot populate; misreading the header-collection requirement.","solutions":["Declare the header collection parameter as IDictionary<string,string> (or a type assignable from it, e.g. Dictionary<string,string>).","For multi-valued headers use the supported header binding rather than a custom collection type.","Confirm the parameter carries the correct header-collection attribute."],"exampleFix":"// before\n[Get(\"/search\")] Task SearchAsync([HeaderCollection] List<KeyValuePair<string,string>> h);\n\n// after\n[Get(\"/search\")] Task SearchAsync([HeaderCollection] IDictionary<string,string> h);","handlingStrategy":"type-guard","validationCode":"if (!typeof(T).IsAssignableFrom(typeof(IDictionary<string,string>)))\n    throw new ArgumentException(\"Header collection parameter must accept IDictionary<string,string>.\");","typeGuard":"static bool IsHeaderCollectionType<T>() => typeof(T).IsAssignableFrom(typeof(IDictionary<string,string>));","tryCatchPattern":null,"preventionTips":["Use IDictionary<string,string> (or Dictionary<string,string>) for header-collection parameters.","Avoid List/array/record types for header collections.","Review header bindings during code review."],"tags":["refit","headers","attributes","type-binding","design-time"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}