{"record":{"id":"0d7906ba281d89d0","repo":"App-vNext/Polly","slug":"unable-to-find-a-generic-resilience-pipeline-of","errorCode":null,"errorMessage":"Unable to find a generic resilience pipeline of '{typeof(TResult).Name}' associated with the key '{key}'. Please ensure that either the generic resilience pipeline or the generic builder is registered.","messagePattern":"Unable to find a generic resilience pipeline of '(.+?)' associated with the key '(.+?)'\\. Please ensure that either the generic resilience pipeline or the generic builder is registered\\.","errorType":"exception","errorClass":"KeyNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Polly.Core/Registry/ResiliencePipelineProvider.cs","lineNumber":43,"sourceCode":"        throw new KeyNotFoundException($\"Unable to find a resilience pipeline associated with the key '{key}'. \" +\n            $\"Please ensure that either the resilience pipeline or the builder is registered.\");\n    }\n\n    /// <summary>\n    /// Retrieves a generic resilience pipeline from the provider using the specified key.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of result that the resilience pipeline handles.</typeparam>\n    /// <param name=\"key\">The key used to identify the resilience pipeline.</param>\n    /// <returns>The resilience pipeline associated with the specified key.</returns>\n    /// <exception cref=\"KeyNotFoundException\">Thrown when no resilience pipeline is found for the specified key.</exception>\n    public virtual ResiliencePipeline<TResult> GetPipeline<TResult>(TKey key)\n    {\n        if (TryGetPipeline<TResult>(key, out var pipeline))\n        {\n            return pipeline;\n        }\n\n        throw new KeyNotFoundException($\"Unable to find a generic resilience pipeline of '{typeof(TResult).Name}' associated with the key '{key}'. \" +\n            $\"Please ensure that either the generic resilience pipeline or the generic builder is registered.\");\n    }\n\n    /// <summary>\n    /// Tries to get a resilience pipeline from the provider using the specified key.\n    /// </summary>\n    /// <param name=\"key\">The key used to identify the resilience pipeline.</param>\n    /// <param name=\"pipeline\">The output resilience pipeline if found, <see langword=\"null\"/> otherwise.</param>\n    /// <returns><see langword=\"true\"/> if the pipeline was found, <see langword=\"false\"/> otherwise.</returns>\n    public abstract bool TryGetPipeline(TKey key, [NotNullWhen(true)] out ResiliencePipeline? pipeline);\n\n    /// <summary>\n    /// Tries to get a generic resilience pipeline from the provider using the specified key.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of result that the resilience pipeline handles.</typeparam>\n    /// <param name=\"key\">The key used to identify the resilience pipeline.</param>\n    /// <param name=\"pipeline\">The output resilience pipeline if found, <see langword=\"null\"/> otherwise.</param>\n    /// <returns><see langword=\"true\"/> if the pipeline was found, <see langword=\"false\"/> otherwise.</returns>","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly.Core/Registry/ResiliencePipelineProvider.cs#L25-L61","documentation":"The generic GetPipeline<TResult>(key) throws KeyNotFoundException when no generic pipeline or generic builder for that exact TResult was registered under the key. Generic and non-generic pipelines live in separate namespaces per key, so a non-generic registration will not satisfy a generic lookup.","triggerScenarios":"Calling provider.GetPipeline<string>(key) when only a non-generic pipeline was registered under key, or when only a different TResult was registered. Also when the generic builder was never added.","commonSituations":"Registering a builder as non-generic but resolving as generic; TResult mismatch (e.g. registered HttpResponseMessage but resolving as object); assuming generic resolution falls back to non-generic.","solutions":["Register a generic builder/pipeline for the exact TResult: registry.TryAddPipeline<TResult>(key, ...) or TryAddBuilder<TResult>(...).","If the pipeline is genuinely type-agnostic, resolve the non-generic GetPipeline(key) and wrap with .AsPipeline<TResult>() explicitly.","Confirm the TResult used at resolution matches the one used at registration, including namespace."],"exampleFix":"// before\nregistry.TryAddPipeline(\"api\", b => b.AddRetry(new()));\nvar p = provider.GetPipeline<HttpResponseMessage>(\"api\"); // throws\n\n// after\nregistry.TryAddPipeline<HttpResponseMessage>(\"api\", b => b.AddRetry(new RetryStrategyOptions<HttpResponseMessage>()));\nvar p = provider.GetPipeline<HttpResponseMessage>(\"api\");","handlingStrategy":"validation","validationCode":"if (provider.TryGetPipeline<TResult>(key, out var pipeline)) {\n    // use pipeline\n} else {\n    // register the generic pipeline/builder for TResult, or fall back\n}","typeGuard":null,"tryCatchPattern":"try { var p = provider.GetPipeline<TResult>(key); }\ncatch (KeyNotFoundException ex) when (ex.Message.Contains(typeof(TResult).Name)) {\n    // register generic builder for TResult or use non-generic pipeline\n}","preventionTips":["Register generic pipelines with the exact TResult you will resolve.","Keep TResult consistent (same namespace/assembly) between registration and resolution.","Use TryGetPipeline<TResult> to guard against optional keys."],"tags":["registry","key-not-found","pipeline-provider","generic","configuration","polly-core"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}