elsa-workflows/elsa-core · error · NotSupportedException

Content of type is not supported.

Error message

Content of type {content.GetType()} is not supported.

What it means

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.

Solutions

  1. Convert the content to byte[] before passing it, e.g. Encoding.UTF8.GetBytes(jsonString) or File.ReadAllBytes(path).
  2. Pass a Stream (e.g., new MemoryStream(bytes) or a FileStream) for large payloads to avoid buffering.
  3. If the content is text/JSON, use the appropriate text-based content path of the activity rather than the binary content factory.

Example fix

// before
var content = "raw-file-bytes-as-string";
BinaryContentFactory.CreateHttpContent(content, "application/octet-stream");
// after
var content = Encoding.UTF8.GetBytes("raw-file-bytes-as-string");
BinaryContentFactory.CreateHttpContent(content, "application/octet-stream");
Defensive patterns

Strategy: type-guard

Validate before calling

bool IsSupportedBinaryContent(object content) => content is byte[] or Stream;

Type guard

HttpContent? TryCreateHttpContent(object content, string contentType) =>
    content switch
    {
        byte[] bytes => new ByteArrayContent(bytes),
        Stream stream => new StreamContent(stream),
        string s => new ByteArrayContent(System.Text.Encoding.UTF8.GetBytes(s)),
        _ => null
    };

Try / catch

try
{
    var httpContent = factory.CreateHttpContent(content, contentType);
}
catch (NotSupportedException ex)
{
    logger.LogError(ex, "Unsupported content type {Type}; convert to byte[] or Stream first", content.GetType());
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/7c55620fdf400598. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Http/ContentWriters/BinaryContentFactory.cs:20

namespace Elsa.Http.ContentWriters;

/// <summary>
/// Creates a <see cref="HttpContent"/> object for application/octet-stream.
/// </summary>
public class BinaryContentFactory : IHttpContentFactory
{
    /// <inheritdoc />
    public IEnumerable<string> SupportedContentTypes => [MediaTypeNames.Application.Octet];

    /// <inheritdoc />
    public HttpContent CreateHttpContent(object content, string contentType)
    {
        return content switch
        {
            byte[] bytes => new ByteArrayContent(bytes),
            Stream stream => new StreamContent(stream),
            _ => throw new NotSupportedException($"Content of type {content.GetType()} is not supported.")
        };
    }
}

View on GitHub (pinned to fe9217bdfa)