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
- Use a content serializer that implements IStreamingContentSerializer (e.g. the System.Text.Json serializer with streaming support)
- Implement IStreamingContentSerializer on your custom IHttpContentSerializer to provide incremental deserialization
- Change the method return type away from IAsyncEnumerable<T> to a buffered type if streaming is not required
- 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
- Use a content serializer that implements IStreamingContentSerializer for streaming endpoints
- Add a startup check that the serializer supports streaming when IAsyncEnumerable methods exist
- Keep streaming and non-streaming serializers aligned to the same JSON stack
- Write an integration test that consumes the first element of every IAsyncEnumerable method
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
- The content serializer can't be null
- This interface needs the reflection request builder, which i
- SystemTextJsonQueryConverter requires RefitSettings.ContentS
- Sequence contains more than one matching element
- Sequence contains no matching element
AI-assisted analysis of reactiveui/refit@b455f65ecc (2026-08-13).
Data as JSON: /api/errors/9d6cc83ef857237c.
Report an issue: GitHub.