{"record":{"id":"f35dd307d3638737","repo":"reactiveui/refit","slug":"multipart-requests-may-not-contain-a-body-paramete","errorCode":null,"errorMessage":"Multipart requests may not contain a Body parameter","messagePattern":"Multipart requests may not contain a Body parameter","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Refit.Reflection/RestMethodInfoInternal.cs","lineNumber":616,"sourceCode":"    /// than one parameter carries <see cref=\"BodyAttribute\"/>.</exception>\n    internal Tuple<BodySerializationMethod, bool, int>? FindBodyParameter(\n        ParameterInfo[] parameterArray,\n        ParameterAttributeSet[] sets,\n        bool isMultipart,\n        HttpMethod method)\n    {\n        // The body parameter is found using the following logic / order of precedence:\n        // 1) [Body] attribute\n        // 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);","sourceCodeStart":598,"sourceCodeEnd":634,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.Reflection/RestMethodInfoInternal.cs#L598-L634","documentation":"Thrown by the body-resolution logic when a method is marked [Multipart] and one of its parameters also carries a [Body] attribute. A multipart request is by definition a collection of named parts (streams, files, objects) and cannot have a single serialized body; the two annotations are mutually exclusive, so Refit refuses to build the request.","triggerScenarios":"An interface method with [Multipart] on the method AND [Body] on a parameter, e.g. `[Post(\"/upload\")] [Multipart] Task UploadAsync([Body] MyDto dto, StreamPart file)`. The presence of both is the sole trigger.","commonSituations":"Migrating a JSON-body endpoint to a file-upload endpoint and forgetting to remove [Body]; attempting to send a DTO alongside a file inside a multipart form by annotating the DTO with [Body].","solutions":["Remove [Body] from the parameter — multipart parts are sent by passing objects/StreamPart without [Body].","If you need to send a DTO inside multipart, pass it as an unannotated complex parameter (Refit serializes it as a part) or break the operation into a separate non-multipart JSON call.","Keep [Multipart] only when you actually have multi-part content (files, streams); drop it if you only need a single JSON body."],"exampleFix":"// before\n[Post(\"/upload\")]\n[Multipart]\nTask UploadAsync([Body] UploadRequest req, StreamPart file);\n\n// after — the DTO becomes a multipart part, no [Body]\n[Post(\"/upload\")]\n[Multipart]\nTask UploadAsync(UploadRequest req, StreamPart file);","handlingStrategy":"validation","validationCode":"// Reject interface methods combining [Multipart] and a [Body] parameter.\nforeach (var m in typeof(IMyApi).GetMethods())\n{\n    var multipart = m.GetCustomAttribute<MultipartAttribute>() is not null;\n    var hasBody = m.GetParameters().Any(p => p.GetCustomAttribute<BodyAttribute>() is not null);\n    if (multipart && hasBody)\n        throw new InvalidOperationException($\"{m.Name}: [Multipart] and [Body] are mutually exclusive.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember multipart requests are composed of parts — never annotate a part with [Body].","When converting a JSON endpoint to upload, explicitly remove the [Body] attribute.","Use a code-review/analyzed check that flags [Multipart]+[Body] co-occurrence."],"tags":["multipart","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"}