{"record":{"id":"b40f27b8c61f8680","repo":"reactiveui/refit","slug":"sequence-contains-no-matching-element","errorCode":null,"errorMessage":"Sequence contains no matching element","messagePattern":"Sequence contains no matching element","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/Refit.HttpClientFactory/HttpClientFactoryCore.cs","lineNumber":388,"sourceCode":"        var methods = typeof(RequestBuilder).GetMethods(BindingFlags.Public | BindingFlags.Static);\n        MethodInfo? match = null;\n        for (var i = 0; i < methods.Length; i++)\n        {\n            var method = methods[i];\n            if (!method.IsGenericMethodDefinition || method.GetParameters().Length != 1)\n            {\n                continue;\n            }\n\n            if (match is not null)\n            {\n                throw new InvalidOperationException(\"Sequence contains more than one matching element\");\n            }\n\n            match = method;\n        }\n\n        return match ?? throw new InvalidOperationException(\"Sequence contains no matching element\");\n    }\n\n    /// <summary>Configures the primary and authorization handlers for a keyed Refit client from its settings.</summary>\n    /// <param name=\"builder\">The HTTP client builder to configure.</param>\n    /// <param name=\"settingsResolver\">Resolves the settings holder for the keyed client from a service provider.</param>\n    private static void ConfigureKeyedHandlers(\n        IHttpClientBuilder builder,\n        Func<IServiceProvider, ISettingsFor> settingsResolver)\n    {\n        _ = builder.ConfigurePrimaryHttpMessageHandler(serviceProvider =>\n            settingsResolver(serviceProvider).Settings?.HttpMessageHandlerFactory?.Invoke() ?? new HttpClientHandler());\n\n        _ = builder.ConfigureAdditionalHttpMessageHandlers((handlers, serviceProvider) =>\n        {\n            if (settingsResolver(serviceProvider).Settings?.AuthorizationHeaderValueGetter is not { } getToken)\n            {\n                return;\n            }","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.HttpClientFactory/HttpClientFactoryCore.cs#L370-L406","documentation":"The companion no-match guard of the ForType reflection lookup: zero single-parameter generic methods were found on RequestBuilder. As with error 0, the comments flag this as unreachable in a matched build, so seeing it means the loaded Refit core assembly is a different version whose public RequestBuilder.ForType signature the HttpClientFactory code does not recognize.","triggerScenarios":"FindRequestBuilderGenericForTypeMethod() iterates RequestBuilder.GetMethods() and finds no public static open-generic method with exactly one parameter. Occurs when the core Refit version is older (or newer) than the HttpClientFactory integration expects, e.g. core 6.x loaded while the factory integration is 8.x.","commonSituations":"Downgrading only the Refit core package; a transitive dependency pins an old Refit; Refit.HttpClientFactory upgraded without upgrading Refit; mismatched Refit source-link/debug build loaded.","solutions":["Set every Refit.* package to one consistent version and restore.","Inspect the loaded assembly with 'dotnet list package --include-transitive' or Assembly.Load events to confirm which Refit.dll is actually resolved.","Do a clean build (rm -rf bin obj + dotnet restore) to eliminate a stale cached assembly.","Use Directory.Packages.props to enforce a single Refit version across the solution."],"exampleFix":"// before\n//   <PackageReference Include=\"Refit.HttpClientFactory\" Version=\"8.0.0\" />\n//   <PackageReference Include=\"Refit\" Version=\"6.3.0\" />  // transitive, too old\n// after\n//   <PackageReference Include=\"Refit.HttpClientFactory\" Version=\"8.0.0\" />\n//   <PackageReference Include=\"Refit\" Version=\"8.0.0\" />","handlingStrategy":"validation","validationCode":"var found = typeof(Refit.RequestBuilder)\n    .GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)\n    .Any(m => m.IsGenericMethodDefinition && m.GetParameters().Length == 1);\nif (!found)\n    throw new InvalidOperationException(\"Loaded Refit core is missing the expected ForType method; align Refit.* package versions.\");","typeGuard":null,"tryCatchPattern":"try { services.AddRefitClient<IMyApi>(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"no matching element\"))\n{\n    throw new InvalidOperationException(\"Refit version mismatch: upgrade/pin the Refit core package to match Refit.HttpClientFactory.\", ex);\n}","preventionTips":["Keep Refit core and Refit.HttpClientFactory at the same version.","Block transitive downgrades of Refit with central package management.","Validate the loaded Refit assembly version in a startup check."],"tags":["refit","httpclientfactory","versioning","reflection","configuration"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}