{"record":{"id":"a9047270d4470949","repo":"reactiveui/refit","slug":"argument-list-to-method-methodinfo-name-can-on","errorCode":null,"errorMessage":"Argument list to method \"{methodInfo.Name}\" can only contain a single CancellationToken","messagePattern":"Argument list to method \"(.+?)\" can only contain a single CancellationToken","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Refit.Reflection/RestMethodInfoInternal.ParameterBinding.cs","lineNumber":386,"sourceCode":"\n    /// <summary>Finds the single cancellation token parameter for the method.</summary>\n    /// <param name=\"methodInfo\">The reflected method information.</param>\n    /// <returns>The cancellation token parameter, or null when none is present.</returns>\n    /// <exception cref=\"ArgumentException\"><paramref name=\"methodInfo\"/> declares more than one <c>CancellationToken</c> parameter.</exception>\n    internal static ParameterInfo? FindCancellationTokenParameter(MethodInfo methodInfo)\n    {\n        var parameters = methodInfo.GetParameters();\n        ParameterInfo? cancellationTokenParam = null;\n        for (var i = 0; i < parameters.Length; i++)\n        {\n            if (!IsCancellationTokenParameter(parameters[i]))\n            {\n                continue;\n            }\n\n            if (cancellationTokenParam is not null)\n            {\n                throw new ArgumentException(\n                    $\"Argument list to method \\\"{methodInfo.Name}\\\" can only contain a single CancellationToken\");\n            }\n\n            cancellationTokenParam = parameters[i];\n        }\n\n        return cancellationTokenParam;\n    }\n\n    /// <summary>Finds and validates the <c>[Url]</c> parameter that supplies the absolute request URI, ensuring the\n    /// method does not also declare a path template.</summary>\n    /// <param name=\"parameterArray\">The array of method parameters.</param>\n    /// <param name=\"sets\">The classified attribute set for each parameter.</param>\n    /// <param name=\"relativePath\">The method's relative path template.</param>\n    /// <returns>The index of the <c>[Url]</c> parameter, or a negative value when none is present.</returns>\n    /// <exception cref=\"ArgumentException\">More than one parameter carries <c>[Url]</c>, the parameter is not a\n    /// <see cref=\"string\"/> or <see cref=\"Uri\"/>, or a <c>[Url]</c> parameter is combined with a non-empty path\n    /// template.</exception>","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.Reflection/RestMethodInfoInternal.ParameterBinding.cs#L368-L404","documentation":"Refit allows exactly one CancellationToken per method, which it wires to the request so cancellation propagates. The scan records the first CancellationToken parameter and throws on the second. Two tokens would create ambiguity about which one governs the request lifetime.","triggerScenarios":"An interface method declares two parameters of type CancellationToken.","commonSituations":"Copy-paste of a CancellationToken; combining a base-interface token with a method-level token; refactor that duplicated the parameter.","solutions":["Keep a single CancellationToken parameter (conventionally the last parameter) on the method.","If two sources of cancellation exist, link them into one token before calling and pass that single token."],"exampleFix":"// before\n[Get(\"/x\")] Task GetAsync(CancellationToken c1, CancellationToken c2);\n\n// after\n[Get(\"/x\")] Task GetAsync(CancellationToken cts);\n// caller links: using var linked = CancellationTokenSource.CreateLinkedTokenSource(c1, c2);","handlingStrategy":"validation","validationCode":"static void AssertSingleCancellationToken(MethodInfo m) {\n    var count = m.GetParameters().Count(p => p.ParameterType == typeof(System.Threading.CancellationToken));\n    if (count > 1) throw new InvalidOperationException(\"Multiple CancellationToken params on \" + m.Name);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare one CancellationToken per method (conventionally last).","Link multiple cancellation sources into one token before calling.","Review method signatures during refactor."],"tags":["refit","cancellation","design-time"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}