reactiveui/refit · error · NotSupportedException

The configured IHttpContentSerializer does not support strea

Error message

The configured IHttpContentSerializer does not support streaming responses. Implement IStreamingContentSerializer to return an IAsyncEnumerable<T>.

What it means

StreamResponseAsync throws NotSupportedException when the configured IHttpContentSerializer does not also implement IStreamingContentSerializer. Streaming responses (IAsyncEnumerable<T>) require incremental deserialization, which the base content-serializer interface does not provide; the request is disposed before throwing.

Source

Thrown at src/Refit/RequestExecutionHelpers.cs:199

    /// <param name="cancellationToken">A token to cancel streaming.</param>
    /// <returns>An asynchronous sequence of deserialized elements.</returns>
    /// <exception cref="NotSupportedException">The serializer configured on <paramref name="settings"/> does not implement <see cref="IStreamingContentSerializer"/>.</exception>
    [System.Diagnostics.CodeAnalysis.SuppressMessage(
        "Design",
        "SST2307:Generic method type parameters should be inferable from the parameters",
        Justification = "Type parameter intentionally specified explicitly by generated and reflection callers.")]
    internal static IAsyncEnumerable<T?> StreamResponseAsync<T>(
        HttpClient client,
        HttpRequestMessage request,
        RefitSettings settings,
        bool applyAuthorizationHeader,
        int timeoutMilliseconds,
        CancellationToken cancellationToken)
    {
        if (settings.ContentSerializer is not IStreamingContentSerializer streamingSerializer)
        {
            request.Dispose();
            throw new NotSupportedException(
                $"The configured {nameof(IHttpContentSerializer)} does not support streaming responses. Implement {nameof(IStreamingContentSerializer)} to return an IAsyncEnumerable<T>.");
        }

        var (token, timeoutSource) = CreateTimeoutToken(timeoutMilliseconds, cancellationToken);

        return StreamResponseIteratorAsync<T>(
            client,
            request,
            settings,
            streamingSerializer,
            applyAuthorizationHeader,
            timeoutSource,
            token);
    }

    /// <summary>Populates an empty Authorization header through the configured token getter, removing the header when the getter returns an empty token.</summary>
    /// <param name="request">The request to modify.</param>
    /// <param name="settings">The Refit settings to use.</param>

View on GitHub (pinned to b455f65ecc)

Solutions

  1. Use a content serializer that implements IStreamingContentSerializer (e.g. the System.Text.Json serializer with streaming support)
  2. Implement IStreamingContentSerializer on your custom IHttpContentSerializer to provide incremental deserialization
  3. Change the method return type away from IAsyncEnumerable<T> to a buffered type if streaming is not required
  4. Register the streaming-capable serializer in RefitSettings before resolving the client

Example fix

// before
var settings = new RefitSettings(new MyBasicContentSerializer());
var api = RestService.For<IStreamApi>(host, settings);
await foreach (var item in api.StreamAsync()) { } // throws - no streaming support

// after
var settings = new RefitSettings(new SystemTextJsonContentSerializer()); // implements IStreamingContentSerializer
var api = RestService.For<IStreamApi>(host, settings);
await foreach (var item in api.StreamAsync()) { }
Defensive patterns

Strategy: type-guard

Validate before calling

if (settings.ContentSerializer is not IStreamingContentSerializer)
    throw new NotSupportedException(
        "A streaming-capable serializer is required for IAsyncEnumerable<T> endpoints.");
var api = RestService.For<IStreamApi>(host, settings);

Type guard

static bool SupportsStreaming(RefitSettings s) =>
    s.ContentSerializer is IStreamingContentSerializer;

Try / catch

try { await foreach (var item in api.StreamAsync()) { /* ... */ } }
catch (NotSupportedException ex) when (ex.Message.Contains("streaming responses"))
{
    // swap in an IStreamingContentSerializer or change the return type
}

Prevention

When it happens

Trigger: A generated or reflection interface method returns IAsyncEnumerable<T> and the RefitSettings.ContentSerializer is a serializer that only implements IHttpContentSerializer (e.g. a basic custom one) rather than IStreamingContentSerializer.

Common situations: Adding a streaming endpoint while using a custom serializer that lacks streaming support; using the default serializer in an older version before streaming was wired; substituting a Newtonsoft.Json-based serializer that does not implement the streaming interface.

Related errors


AI-assisted analysis of reactiveui/refit@b455f65ecc (2026-08-13). Data as JSON: /api/errors/9d6cc83ef857237c. Report an issue: GitHub.