reactiveui/refit · error · NotSupportedException
This interface needs the reflection request builder, which i
Error message
This interface needs the reflection request builder, which is not installed. Add a reference to the Refit.Reflection NuGet package to opt in to it, or change the interface so every method generates inline (the RF006 diagnostic reports the methods that cannot) and use a generated client via RestService.ForGenerated or AddRefitGeneratedClient.
What it means
CreateFactory throws NotSupportedException when the Refit.Reflection assembly is not loaded, because an interface method requires the runtime reflection request builder (it cannot be generated inline). The message directs you to either add the Refit.Reflection NuGet package or rework the interface so every method generates inline and switch to a generated client.
Source
Thrown at src/Refit/ReflectionRequestBuilderResolver.cs:37
/// <summary>The lazily resolved factory instance.</summary>
private static IRequestBuilderFactory? _factory;
/// <summary>Gets the reflection request-builder factory, loading the Refit.Reflection assembly on first use.</summary>
/// <returns>The factory instance.</returns>
/// <exception cref="NotSupportedException">The Refit.Reflection package is not installed.</exception>
[RequiresUnreferencedCode("The reflection request builder requires runtime type lookup and request metadata.")]
internal static IRequestBuilderFactory GetFactory() => _factory ??= CreateFactory();
/// <summary>Loads and instantiates the reflection request-builder factory.</summary>
/// <returns>The factory instance.</returns>
/// <exception cref="NotSupportedException">The Refit.Reflection assembly is not present, so the factory type cannot be loaded.</exception>
[RequiresUnreferencedCode("The reflection request builder requires runtime type lookup and request metadata.")]
[ExcludeFromCodeCoverage] // The not-installed throw is unreachable in-process: Refit.Reflection is always present when this resolver runs.
internal static IRequestBuilderFactory CreateFactory() =>
Type.GetType(FactoryTypeName, throwOnError: false) is { } factoryType
&& Activator.CreateInstance(factoryType) is IRequestBuilderFactory factory
? factory
: throw new NotSupportedException(
"This interface needs the reflection request builder, which is not installed. Add a reference to "
+ "the Refit.Reflection NuGet package to opt in to it, or change the interface so every method "
+ "generates inline (the RF006 diagnostic reports the methods that cannot) and use a generated "
+ "client via RestService.ForGenerated or AddRefitGeneratedClient.");
}
View on GitHub (pinned to b455f65ecc)
Solutions
- Add a PackageReference to Refit.Reflection to opt into the runtime reflection builder
- Refactor the offending interface methods so each generates inline (resolve the RF006 diagnostics) and switch to RestService.ForGenerated / AddRefitGeneratedClient
- Confirm the Refit.Reflection assembly is actually copied to the output (check for trimming/publish settings that exclude it)
- Run the source generator and fix every RF006 error before relying on the generated client alone
Example fix
// before var api = RestService.For<IMixedApi>(client); // IMixedApi has a non-generatable method and Refit.Reflection is absent => throws // after (option A - add reflection support) // <PackageReference Include="Refit.Reflection" Version="..." /> var api = RestService.For<IMixedApi>(client); // after (option B - make it generatable and use the generated client) var api = RestService.ForGenerated<IMixedApi>(client);
Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the interface fully generates inline before relying on the generated client.
// Build the project and assert the RF006 diagnostic count is zero:
// dotnet build /p:ReportAnalyzer=true
// Then use the generated client; only fall back to reflection with Refit.Reference present.
bool allMethodsGenerateInline = /* check RF006 diagnostics == 0 */ true;
if (!allMethodsGenerateInline)
throw new InvalidOperationException(
"Interface has non-generatable methods; add Refit.Reflection or refactor them."); Try / catch
try { var api = RestService.For<IMixedApi>(client); }
catch (NotSupportedException ex) when (ex.Message.Contains("reflection request builder"))
{
// either add Refit.Reflection or refactor the interface to be fully generatable
} Prevention
- Add the Refit.Reflection package reference whenever you use RestService.For on mixed interfaces
- Drive RF006 diagnostics to zero to enable the pure generated-client path
- Verify Refit.Reflection is present in publish output (watch for trimming)
- Prefer RestService.ForGenerated / AddRefitGeneratedClient for AOT-friendly apps
When it happens
Trigger: An interface contains at least one method that the source generator cannot emit inline (reported by the RF006 diagnostic), and the app calls RestService.For (reflection path) while the Refit.Reflection package is not referenced. The resolver loads the factory via Type.GetType and fails.
Common situations: Trimming/missing the Refit.Reflection reference in a project that still uses RestService.For; using a method shape the generator rejects while only shipping the generated client package; AOT scenarios where reflection support was deliberately excluded; package downgrade removing Refit.Reflection.
Related errors
- This Refit client was created with the generated-only API, b
- Sequence contains more than one matching element
- Sequence contains no matching element
- targetInterface must be an Interface
- The configured IHttpContentSerializer does not support strea
AI-assisted analysis of reactiveui/refit@b455f65ecc (2026-08-13).
Data as JSON: /api/errors/cb3a3dbc14a0a192.
Report an issue: GitHub.