{"record":{"id":"73f43f81cf23dcbe","repo":"dotnet/yarp","slug":"this-version-of-yarp-is-incompatible-with-the-curr","errorCode":null,"errorMessage":"This version of YARP is incompatible with the current version of ASP.NET Core.","messagePattern":"This version of YARP is incompatible with the current version of ASP\\.NET Core\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"critical","filePath":"src/ReverseProxy/Configuration/IYarpOutputCachePolicyProvider.cs","lineNumber":40,"sourceCode":"internal sealed class YarpOutputCachePolicyProvider : IYarpOutputCachePolicyProvider\n{\n    // Workaround for https://github.com/dotnet/yarp/issues/2598 to make YARP work with NativeAOT on .NET 8. This is not needed on .NET 9+.\n    [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]\n    private static readonly Type s_OutputCacheOptionsType = typeof(OutputCacheOptions);\n\n    private readonly OutputCacheOptions _outputCacheOptions;\n\n    private readonly IDictionary _policyMap;\n\n    public YarpOutputCachePolicyProvider(IOptions<OutputCacheOptions> outputCacheOptions)\n    {\n        ArgumentNullException.ThrowIfNull(outputCacheOptions?.Value);\n        _outputCacheOptions = outputCacheOptions.Value;\n\n        var property = s_OutputCacheOptionsType.GetProperty(\"NamedPolicies\", BindingFlags.Instance | BindingFlags.NonPublic);\n        if (property == null || !typeof(IDictionary).IsAssignableFrom(property.PropertyType))\n        {\n            throw new NotSupportedException(\"This version of YARP is incompatible with the current version of ASP.NET Core.\");\n        }\n        _policyMap = (property.GetValue(_outputCacheOptions, null) as IDictionary) ?? new Dictionary<string, object>();\n    }\n\n    public ValueTask<object?> GetPolicyAsync(string policyName)\n    {\n        return ValueTask.FromResult(_policyMap[policyName]);\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":50,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/src/ReverseProxy/Configuration/IYarpOutputCachePolicyProvider.cs#L22-L50","documentation":"Thrown by YarpOutputCachePolicyProvider constructor when it cannot find the internal NamedPolicies property on OutputCacheOptions via reflection. YARP relies on an internal ASP.NET Core member to look up output-cache policies by name; if the member is absent or has an incompatible type, the YARP build is incompatible with the installed ASP.NET Core version. This is a version-coupling guard.","triggerScenarios":"Constructing YarpOutputCachePolicyProvider (resolved when output-cache policies are used with YARP) against an ASP.NET Core version where OutputCacheOptions.NamedPolicies was renamed, moved, removed, or changed type.","commonSituations":"Upgrading or downgrading ASP.NET Core without a matching YARP version. Using a preview/nightly ASP.NET Core build that changed internal layout. Mismatched YARP and ASP.NET Core package versions.","solutions":["Align YARP and ASP.NET Core versions — use the YARP release that targets your ASP.NET Core version.","Update the Microsoft.Extensions.Caching.Memory / Microsoft.AspNetCore.OutputCaching packages to match.","If you do not need output-cache integration, avoid configuring OutputCachePolicy on routes to bypass this provider."],"exampleFix":"// before — mismatched versions in .csproj\n<PackageReference Include=\"Yarp.ReverseProxy\" Version=\"2.0.0\" />\n<FrameworkReference Include=\"Microsoft.AspNetCore.App\" Version=\"7.0.0\" />\n// after — aligned versions\n<PackageReference Include=\"Yarp.ReverseProxy\" Version=\"2.1.0\" />\n<FrameworkReference Include=\"Microsoft.AspNetCore.App\" Version=\"8.0.0\" />","handlingStrategy":"validation","validationCode":"// Verify compatibility at startup before relying on output-cache policy lookup\nvar prop = typeof(OutputCacheOptions).GetProperty(\"NamedPolicies\", BindingFlags.Instance | BindingFlags.NonPublic);\nif (property is null || !typeof(IDictionary).IsAssignableFrom(property.PropertyType))\n    logger.LogWarning(\"YARP/ASP.NET Core output-cache incompatibility detected\");","typeGuard":"// n/a — runtime reflection check","tryCatchPattern":"try { services.AddSingleton<YarpOutputCachePolicyProvider>(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"incompatible\"))\n{ logger.LogCritical(ex, \"Upgrade YARP or ASP.NET Core to compatible versions.\"); throw; }","preventionTips":["Pin YARP and ASP.NET Core to versions known to be compatible.","Run a smoke test that constructs the output-cache provider after framework updates.","Avoid output-cache integration unless versions are aligned."],"tags":["version-compat","output-cache","reflection","aspnetcore","startup"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}