reactiveui/refit · error · NotSupportedException
SystemTextJsonQueryConverter requires RefitSettings.ContentS
Error message
SystemTextJsonQueryConverter requires RefitSettings.ContentSerializer to be a SystemTextJsonContentSerializer.
What it means
SystemTextJsonQueryConverter<T>.Flatten throws NotSupportedException when RefitSettings.ContentSerializer is not a SystemTextJsonContentSerializer. The converter reuses the serializer's JsonSerializerOptions to flatten the value, so a different serializer implementation cannot supply those options.
Source
Thrown at src/Refit/SystemTextJsonQueryConverter.cs:35
/// The value's runtime type is walked, so a polymorphic value contributes its actual properties. When the configured
/// serializer uses a source-generated <c>TypeInfoResolver</c> the walk is reflection- and AOT-free; otherwise it falls
/// back to System.Text.Json's reflection resolver. Nested objects are flattened under a dotted key; collections use the
/// configured <see cref="RefitSettings.CollectionFormat"/>.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("{ToString(),nq}")]
public sealed class SystemTextJsonQueryConverter<T> : IQueryConverter<T>
{
/// <inheritdoc/>
public void Flatten(T value, string keyPrefix, ref GeneratedQueryStringBuilder builder, RefitSettings settings)
{
if (value is null)
{
return;
}
if (settings.ContentSerializer is not SystemTextJsonContentSerializer serializer)
{
throw new NotSupportedException(
$"SystemTextJsonQueryConverter requires {nameof(RefitSettings)}.{nameof(RefitSettings.ContentSerializer)} to be a {nameof(SystemTextJsonContentSerializer)}.");
}
SystemTextJsonQueryFlattener.FlattenObject(value, keyPrefix, ref builder, settings, serializer.SerializerOptions, 0);
}
}
View on GitHub (pinned to b455f65ecc)
Solutions
- Set RefitSettings.ContentSerializer to a SystemTextJsonContentSerializer so the options are available
- If you must use a different content serializer, write a custom IQueryConverter that does not depend on System.Text.Json options
- Align both the content serializer and the query converter to the same JSON stack
- Register the query converter only for interfaces whose settings use SystemTextJsonContentSerializer
Example fix
// before var settings = new RefitSettings(new NewtonsoftJsonContentSerializer()); settings.QueryConverter = new SystemTextJsonQueryConverter<MyFilter>(); await api.SearchAsync(filter); // throws - serializer mismatch // after var jsonOpts = new JsonSerializerOptions(); var settings = new RefitSettings(new SystemTextJsonContentSerializer(jsonOpts)); settings.QueryConverter = new SystemTextJsonQueryConverter<MyFilter>();
Defensive patterns
Strategy: type-guard
Validate before calling
if (settings.ContentSerializer is not SystemTextJsonContentSerializer)
throw new NotSupportedException(
"SystemTextJsonQueryConverter requires a SystemTextJsonContentSerializer.");
settings.QueryConverter = new SystemTextJsonQueryConverter<MyFilter>(); Type guard
static bool IsSystemTextJson(RefitSettings s) =>
s.ContentSerializer is SystemTextJsonContentSerializer; Try / catch
try { await api.SearchAsync(filter); }
catch (NotSupportedException ex) when (ex.Message.Contains("SystemTextJsonContentSerializer"))
{
// align the content serializer to System.Text.Json or use a custom query converter
} Prevention
- Align the content serializer and the query converter to the same JSON stack
- Add a startup assertion that the serializer matches the registered query converter
- Only register SystemTextJsonQueryConverter when using SystemTextJsonContentSerializer
- Document converter/serializer compatibility in your Refit configuration
When it happens
Trigger: Registering SystemTextJsonQueryConverter<T> as the query converter for a type while RefitSettings.ContentSerializer is a non-System.Text.Json serializer (e.g. Newtonsoft.Json or a custom IHttpContentSerializer). The mismatch is detected on the first call to Flatten for a non-null value.
Common situations: Mixing a Newtonsoft-based content serializer with the System.Text.Json query converter; registering the query converter globally without aligning the content serializer; upgrading Refit and inheriting the converter while the app still uses a legacy serializer.
Related errors
- This interface needs the reflection request builder, which i
- The configured IHttpContentSerializer does not support strea
- Sequence contains more than one matching element
- Sequence contains no matching element
- Unexpected parameter type in a Multipart request. Parameter
AI-assisted analysis of reactiveui/refit@b455f65ecc (2026-08-13).
Data as JSON: /api/errors/dc6a42308c9ea854.
Report an issue: GitHub.