{"record":{"id":"2abee8d8e089a84a","repo":"dotnet/yarp","slug":"no-typeof-t-was-found-for-the-id-lookup","errorCode":null,"errorMessage":"No {typeof(T)} was found for the id '{lookup}'.","messagePattern":"No (.+?) was found for the id '(.+?)'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ReverseProxy/Utilities/ServiceLookupHelper.cs","lineNumber":39,"sourceCode":"            {\n                throw new ArgumentException($\"More than one {typeof(T)} found with the same identifier.\", nameof(services));\n            }\n        }\n\n        return result.ToFrozenDictionary(StringComparer.OrdinalIgnoreCase);\n    }\n\n    public static T GetRequiredServiceById<T>(this FrozenDictionary<string, T> services, string? id, string defaultId)\n    {\n        var lookup = id;\n        if (string.IsNullOrEmpty(lookup))\n        {\n            lookup = defaultId;\n        }\n\n        if (!services.TryGetValue(lookup, out var result))\n        {\n            throw new ArgumentException($\"No {typeof(T)} was found for the id '{lookup}'.\", nameof(id));\n        }\n        return result;\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":44,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Utilities/ServiceLookupHelper.cs#L21-L44","documentation":"Thrown by ServiceLookupHelper.GetRequiredServiceById when a configured policy id cannot be found in the frozen name->policy dictionary. The lookup first substitutes defaultId when the supplied id is null or empty, then does a case-insensitive TryGetValue; on miss it throws ArgumentException(paramName: id). It is reached from request-time middleware (LoadBalancingMiddleware, SessionAffinityMiddleware, PassiveHealthCheckMiddleware) and the active health check monitor when they resolve the policy named in the cluster/route config.","triggerScenarios":"A cluster config sets LoadBalancingPolicy, HealthCheck.Active/Passive policy, SessionAffinity.Policy/FailurePolicy, or an AvailableDestinations policy to a name that no registered policy exposes. For example Cluster.LoadBalancingPolicy = \"LeastRequests\" while only the default policies are registered, or referencing a custom session affinity policy whose Add* registration was never called.","commonSituations":"Typo in the config policy name; referencing a policy that lives in a package/extension not yet added to DI; enabling a policy in config before registering it (e.g. setting HealthCheck.Active.Policy without calling AddActiveHealthCheckPolicy); case-only differences are tolerated but trailing spaces or alternate spellings are not; migrating a policy name after a YARP version rename without updating config.","solutions":["Register the missing policy via the appropriate Add* extension (AddActiveHealthCheckPolicy, AddPassiveHealthCheckPolicy, AddLoadBalancingPolicies, AddSessionAffinityPolicies, etc.).","Correct the policy name in the cluster/route config to exactly match a registered policy's Name.","Omit the policy setting (or set it to null/empty) to fall back to the documented defaultId for that category.","Use the matching config validator (LoadBalancingValidator, HealthCheckValidator, SessionAffinityValidator) which reports the missing policy as a validation error before request time."],"exampleFix":"// before\n\"LoadBalancingPolicy\": \"LeastRequests\"  // not registered\n\n// after\nbuilder.Services.AddLoadBalancingPolicies();\n// and/or use a registered name:\n\"LoadBalancingPolicy\": \"PowerOfTwoChoices\"","handlingStrategy":"validation","validationCode":"// Validate every referenced policy name is registered before serving traffic.\nvar registered = builder.Services.BuildServiceProvider()\n    .GetServices<ILoadBalancingPolicy>().Select(p => p.Name)\n    .ToHashSet(StringComparer.OrdinalIgnoreCase);\nforeach (var cluster in config.Clusters) {\n    var name = cluster.LoadBalancingPolicy;\n    if (!string.IsNullOrEmpty(name) && !registered.Contains(name))\n        Console.Error.WriteLine($\"Unknown LoadBalancingPolicy '{name}' on cluster {cluster.ClusterId}\");\n}","typeGuard":null,"tryCatchPattern":"// Last-resort request-time guard around the resolving middleware.\ntry { /* GetRequiredServiceById call */ }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"was found for the id\")) {\n    context.Response.StatusCode = 502;\n    await context.Response.WriteAsync(\"Upstream policy misconfigured\");\n}","preventionTips":["Rely on YARP's config validators (LoadBalancingValidator, HealthCheckValidator, SessionAffinityValidator) which surface missing policies as validation errors at startup.","Keep policy names in constants and reference the same constant from config and registration.","Add an integration test that loads your config against the real DI container to catch unregistered names.","When you remove or rename a policy registration, grep config files for the old name."],"tags":["configuration","policy-resolution","runtime","missing-registration","yarp"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}