{"record":{"id":"7c55620fdf400598","repo":"elsa-workflows/elsa-core","slug":"content-of-type-content-gettype-is-not-supported","errorCode":null,"errorMessage":"Content of type {content.GetType()} is not supported.","messagePattern":"Content of type (.+?) is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Http/ContentWriters/BinaryContentFactory.cs","lineNumber":20,"sourceCode":"\nnamespace Elsa.Http.ContentWriters;\n\n/// <summary>\n/// Creates a <see cref=\"HttpContent\"/> object for application/octet-stream.\n/// </summary>\npublic class BinaryContentFactory : IHttpContentFactory\n{\n    /// <inheritdoc />\n    public IEnumerable<string> SupportedContentTypes => [MediaTypeNames.Application.Octet];\n\n    /// <inheritdoc />\n    public HttpContent CreateHttpContent(object content, string contentType)\n    {\n        return content switch\n        {\n            byte[] bytes => new ByteArrayContent(bytes),\n            Stream stream => new StreamContent(stream),\n            _ => throw new NotSupportedException($\"Content of type {content.GetType()} is not supported.\")\n        };\n    }\n}","sourceCodeStart":2,"sourceCodeEnd":23,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Http/ContentWriters/BinaryContentFactory.cs#L2-L23","documentation":"BinaryContentFactory.CreateHttpContent converts workflow HTTP response content into an HttpContent for transmission, supporting only byte[] (ByteArrayContent) and Stream (StreamContent). Any other content type reaches the switch's discard arm and throws NotSupportedException naming the offending type. Callers must pass raw binary content or a stream.","triggerScenarios":"CreateHttpContent(content, contentType) is invoked with a content object that is neither byte[] nor Stream — e.g., a string, a JSON-serializable POCO, a Memory<T>, or a custom type passed as the file/binary content of an HTTP response activity.","commonSituations":"Passing a string 'binary' payload instead of Encoding.UTF8.GetBytes(string), passing a MemoryStream-wrapped custom stream type is fine but a POCO is not, or after upgrading/refactoring where content used to be pre-converted to byte[] upstream.","solutions":["Convert the content to byte[] before passing it, e.g. Encoding.UTF8.GetBytes(jsonString) or File.ReadAllBytes(path).","Pass a Stream (e.g., new MemoryStream(bytes) or a FileStream) for large payloads to avoid buffering.","If the content is text/JSON, use the appropriate text-based content path of the activity rather than the binary content factory."],"exampleFix":"// before\nvar content = \"raw-file-bytes-as-string\";\nBinaryContentFactory.CreateHttpContent(content, \"application/octet-stream\");\n// after\nvar content = Encoding.UTF8.GetBytes(\"raw-file-bytes-as-string\");\nBinaryContentFactory.CreateHttpContent(content, \"application/octet-stream\");","handlingStrategy":"type-guard","validationCode":"bool IsSupportedBinaryContent(object content) => content is byte[] or Stream;","typeGuard":"HttpContent? TryCreateHttpContent(object content, string contentType) =>\n    content switch\n    {\n        byte[] bytes => new ByteArrayContent(bytes),\n        Stream stream => new StreamContent(stream),\n        string s => new ByteArrayContent(System.Text.Encoding.UTF8.GetBytes(s)),\n        _ => null\n    };","tryCatchPattern":"try\n{\n    var httpContent = factory.CreateHttpContent(content, contentType);\n}\ncatch (NotSupportedException ex)\n{\n    logger.LogError(ex, \"Unsupported content type {Type}; convert to byte[] or Stream first\", content.GetType());\n}","preventionTips":["Convert strings/POCOs to byte[] (Encoding.UTF8.GetBytes) or Stream before passing binary content.","Centralize content conversion in a helper so raw objects never reach the factory.","Add a unit test asserting CreateHttpContent accepts only byte[] and Stream inputs."],"tags":["http","content-type","unsupported-type","workflow"],"backgroundTag":"unsupported-operation","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}