{"record":{"id":"4becea101fa7a693","repo":"reactiveui/refit","slug":"only-one-parameter-can-be-a-body-parameter","errorCode":null,"errorMessage":"Only one parameter can be a Body parameter","messagePattern":"Only one parameter can be a Body parameter","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Refit.Reflection/RestMethodInfoInternal.cs","lineNumber":625,"sourceCode":"        // 2) POST/PUT/PATCH: Reference type other than string\n        // 3) If there are two reference types other than string, without the body attribute, throw\n        var (bodyAttribute, bodyParameterIndex, hasMultipleBodyParameters) = FindBodyAttribute(sets);\n\n        // multipart requests may not contain a body, implicit or explicit\n        if (isMultipart)\n        {\n            if (bodyAttribute is not null)\n            {\n                throw new ArgumentException(\n                    \"Multipart requests may not contain a Body parameter\");\n            }\n\n            return null;\n        }\n\n        if (hasMultipleBodyParameters)\n        {\n            throw new ArgumentException(\"Only one parameter can be a Body parameter\");\n        }\n\n        // #1, body attribute wins\n        if (bodyAttribute is not null)\n        {\n            return Tuple.Create(\n                bodyAttribute.SerializationMethod,\n                bodyAttribute.Buffered ?? RefitSettings.Buffered,\n                bodyParameterIndex);\n        }\n\n        // Only post/put/patch carry an implicit body.\n        return method.Equals(HttpMethod.Post)\n            || method.Equals(HttpMethod.Put)\n            || method.Equals(_patchMethod)\n            ? FindImplicitBodyParameter(parameterArray, sets)\n            : null;\n    }","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.Reflection/RestMethodInfoInternal.cs#L607-L643","documentation":"Thrown when more than one parameter on a method is explicitly annotated with [Body]. An HTTP request can carry exactly one body, so Refit cannot decide which to serialize as the payload and aborts at interface-analysis time.","triggerScenarios":"A method with two (or more) parameters each carrying [Body], e.g. `Task PostAsync([Body] A a, [Body] B b)`. FindBodyAttribute sets hasMultipleBodyParameters when it sees a second BodyAttribute, and the check fires before any serialization choice.","commonSituations":"Trying to merge two objects into one request body; refactoring a method and leaving a stale [Body]; misunderstanding that [Body] is exclusive.","solutions":["Keep a single [Body] parameter; combine the two objects into one DTO if both must be sent.","Move the other parameter to [Query], [AliasAs], [Header], or make it a route parameter as appropriate.","If you need nested data, redesign the body DTO to contain both rather than passing two bodies."],"exampleFix":"// before\nTask PostAsync([Body] Order order, [Body] Customer customer);\n\n// after — combine into one body DTO, send the rest as query\npublic sealed record CreateOrderRequest(Order Order, Customer Customer);\nTask PostAsync([Body] CreateOrderRequest body, [Query] string tenant);","handlingStrategy":"validation","validationCode":"// Ensure at most one [Body] parameter per method.\nforeach (var m in typeof(IMyApi).GetMethods())\n{\n    var bodyCount = m.GetParameters()\n        .Count(p => p.GetCustomAttribute<BodyAttribute>() is not null);\n    if (bodyCount > 1)\n        throw new InvalidOperationException($\"{m.Name} has {bodyCount} [Body] parameters; only one is allowed.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exactly one [Body] per method; merge multiple objects into a single DTO.","Use [Query]/[AliasAs]/[Header] to bind the other parameters explicitly.","Add a build-time interface-validation test asserting the one-body rule."],"tags":["body","attribute-conflict","reflection-builder"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}