{"record":{"id":"b938e1b51f6deadf","repo":"Devolutions/UniGetUI","slug":"the-request-body-is-required","errorCode":null,"errorMessage":"The request body is required.","messagePattern":"The request body is required\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":400,"severity":"error","filePath":"src/UniGetUI.Interface.IpcApi/IpcServer.cs","lineNumber":1853,"sourceCode":"            {\n                await context.Response.WriteAsJsonAsync(\n                    await action(await ReadJsonBodyAsync<TRequest>(context)),\n                    IpcJson.Options\n                );\n            }\n            catch (InvalidOperationException ex)\n            {\n                context.Response.StatusCode = 400;\n                await context.Response.WriteAsync(ex.Message);\n            }\n        }\n\n        private static async Task<TRequest> ReadJsonBodyAsync<TRequest>(HttpContext context)\n        {\n            using var reader = new StreamReader(context.Request.Body, Encoding.UTF8);\n            var request = IpcJson.Deserialize<TRequest>(await reader.ReadToEndAsync());\n            return request\n                ?? throw new InvalidOperationException(\"The request body is required.\");\n        }\n\n        private static IpcPackageActionRequest BuildPackageActionRequest(HttpRequest request)\n        {\n            return new IpcPackageActionRequest\n            {\n                PackageId = GetRequiredQueryValue(request, \"packageId\"),\n                ManagerName = GetOptionalQueryValue(request, \"manager\"),\n                PackageSource = GetOptionalQueryValue(request, \"packageSource\"),\n                Version = GetOptionalQueryValue(request, \"version\"),\n                Scope = GetOptionalQueryValue(request, \"scope\"),\n                PreRelease = bool.TryParse(request.Query[\"preRelease\"], out bool preRelease)\n                    ? preRelease\n                    : null,\n                Elevated = bool.TryParse(request.Query[\"elevated\"], out bool elevated)\n                    ? elevated\n                    : null,\n                Interactive = bool.TryParse(request.Query[\"interactive\"], out bool interactive)","sourceCodeStart":1835,"sourceCodeEnd":1871,"githubUrl":"https://github.com/Devolutions/UniGetUI/blob/9b1d7d0eab91620fc15c86b36676532095936ae3/src/UniGetUI.Interface.IpcApi/IpcServer.cs#L1835-L1871","documentation":"Thrown by ReadJsonBodyAsync<TRequest> when IpcJson.Deserialize returns null after reading the request body. This happens when the body is empty/whitespace (the deserializer yields null) rather than a JSON syntax error (which throws earlier). The handler returns HTTP 400.","triggerScenarios":"POSTing to a maintenance/action endpoint (HandleManagerMaintenanceActionAsync) with an empty Content-Length, a whitespace-only body, or a body that deserializes to a null reference for the request type.","commonSituations":"Client forgot to attach a JSON body; set Content-Type but sent an empty string; used a GET where the route expects a POST with a body; proxy stripped the body.","solutions":["Send a valid JSON object for the request type, e.g. '{}' for an empty request DTO, with Content-Type: application/json.","On the client, assert a non-empty body before issuing the request.","If the endpoint legitimately accepts no fields, send the empty-object literal '{}' rather than nothing."],"exampleFix":"// before: POST with empty body -> HTTP 400 \"The request body is required.\"\n// after:\nvar content = new StringContent(\"{}\", Encoding.UTF8, \"application/json\");\nvar resp = await httpClient.PostAsync($\"/v3/...?token={token}\", content);","handlingStrategy":"validation","validationCode":"// Client: ensure a non-empty JSON body before POSTing.\nif (string.IsNullOrWhiteSpace(bodyJson))\n    bodyJson = \"{}\";\nvar content = new StringContent(bodyJson, Encoding.UTF8, \"application/json\");\nif (content.Headers.ContentLength == 0) throw new InvalidOperationException(\"body required\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set a JSON body (at least '{}') for POST maintenance endpoints.","Set Content-Type: application/json alongside the body.","Centralize a helper that POSTs {} when no payload fields are needed."],"tags":["ipc","http-400","request-body","json-deserialize"],"backgroundTag":null,"analyzedSha":"9b1d7d0eab91620fc15c86b36676532095936ae3","analyzedAt":"2026-08-13T12:19:18.278Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}