{"record":{"id":"24db5b08ff807076","repo":"reactiveui/refit","slug":"this-refit-client-was-created-with-the-generated-o","errorCode":null,"errorMessage":"This Refit client was created with the generated-only API, but the generated client needs the reflection request builder for '{methodName}'. Enable generated request building for this method or use RestService.For when reflection is acceptable.","messagePattern":"This Refit client was created with the generated-only API, but the generated client needs the reflection request builder for '(.+?)'\\. Enable generated request building for this method or use RestService\\.For when reflection is acceptable\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Refit/GeneratedOnlyRequestBuilder.cs","lineNumber":28,"sourceCode":"{\n    /// <summary>Initializes a new instance of the <see cref=\"GeneratedOnlyRequestBuilder\"/> class.</summary>\n    /// <param name=\"settings\">The settings used by the generated client.</param>\n    internal GeneratedOnlyRequestBuilder(RefitSettings settings) => Settings = settings;\n\n    /// <inheritdoc/>\n    public RefitSettings Settings { get; }\n\n    /// <inheritdoc/>\n    [RequiresUnreferencedCode(\"Building request delegates from reflected method metadata requires generic method metadata to be available at runtime.\")]\n    [RequiresDynamicCode(\"Building request delegates from reflected method metadata requires runtime generic method instantiation.\")]\n    public Func<HttpClient, object[], object?> BuildRestResultFuncForMethod(\n        string methodName,\n        Type[]? parameterTypes = null,\n        Type[]? genericArgumentTypes = null)\n    {\n        var methodContext =\n            $\"This Refit client was created with the generated-only API, but the generated client needs the reflection request builder for '{methodName}'.\";\n        throw new NotSupportedException(\n            string.Concat(\n                methodContext,\n                \" Enable generated request building for this method or use RestService.For when reflection is acceptable.\"));\n    }\n}\n","sourceCodeStart":10,"sourceCodeEnd":34,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit/GeneratedOnlyRequestBuilder.cs#L10-L34","documentation":"Thrown by GeneratedOnlyRequestBuilder.BuildRestResultFuncForMethod — a request builder used when a Refit client is created in generated-only mode (no reflection). It throws unconditionally because that mode forbids building request delegates via reflection; the method it was asked to build ('{methodName}') was not covered by the generated client, so Refit cannot fulfill the call without falling back to reflection.","triggerScenarios":"A Refit interface method that is not implemented by the source generator is invoked on a client built via the generated-only entry point (e.g. RestService.ForGenerated<T> / AddRefitClient with generated-only). The runtime tries to reflect-build the method and hits this NotSupportedException. Common when a method lacks partial/generated coverage or the generator didn't run for that interface.","commonSituations":"Adding a new method to a Refit interface but the source generator didn't regenerate (build/stale issue); using a generic/interface combination the generator doesn't handle; enabling generated-only mode while still relying on reflection-only features; trimming/AOT scenarios where the generated partial is absent.","solutions":["Ensure the source generator ran for the interface (rebuild; verify the generated partial client exists and includes the method).","Use the reflection-capable entry point RestService.For<T> if runtime reflection is acceptable (not AOT).","Confirm the method signature is one the generator supports (e.g. return type, attributes) and that the interface is marked/visible to the generator."],"exampleFix":"// before — generated-only client, method not generated\nvar client = RestService.ForGenerated<IMyApi>(baseUrl);\nawait client.NewMethodAsync(); // throws NotSupportedException\n\n// after — either let the generator produce it (rebuild/fix signature),\n// or use the reflection entry point:\nvar client = RestService.For<IMyApi>(baseUrl);\nawait client.NewMethodAsync();","handlingStrategy":"validation","validationCode":"// Verify the generated client covers the method before calling it in generated-only mode.\n// At build time, ensure the source generator produced a partial client for IMyApi.\n// At runtime, prefer the reflection entry point if the method isn't generated:\nIMyApi client = RuntimeFeature.IsDynamicCodeSupported\n    ? RestService.For<IMyApi>(baseUrl)        // reflection OK\n    : RestService.ForGenerated<IMyApi>(baseUrl); // generated-only (AOT)","typeGuard":null,"tryCatchPattern":"try { await client.MethodAsync(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"generated-only API\"))\n{\n    // Method wasn't generated — fall back to RestService.For<T> (reflection) or regenerate the client.\n    var reflectionClient = RestService.For<IMyApi>(baseUrl);\n    await reflectionClient.MethodAsync();\n}","preventionTips":["Rebuild the project after adding methods so the source generator emits the new partial client.","Reserve generated-only mode for AOT; use RestService.For<T> when reflection is acceptable.","Verify generator support for the method's signature/attributes and that the interface is visible to the generator."],"tags":["source-generator","aot","reflection","request-builder","generated-only"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}