dotnet/yarp · critical · NotSupportedException

This version of YARP is incompatible with the current versio

Error message

This version of YARP is incompatible with the current version of ASP.NET Core.

What it means

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.

Source

Thrown at src/ReverseProxy/Configuration/IYarpOutputCachePolicyProvider.cs:40

internal sealed class YarpOutputCachePolicyProvider : IYarpOutputCachePolicyProvider
{
    // 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+.
    [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
    private static readonly Type s_OutputCacheOptionsType = typeof(OutputCacheOptions);

    private readonly OutputCacheOptions _outputCacheOptions;

    private readonly IDictionary _policyMap;

    public YarpOutputCachePolicyProvider(IOptions<OutputCacheOptions> outputCacheOptions)
    {
        ArgumentNullException.ThrowIfNull(outputCacheOptions?.Value);
        _outputCacheOptions = outputCacheOptions.Value;

        var property = s_OutputCacheOptionsType.GetProperty("NamedPolicies", BindingFlags.Instance | BindingFlags.NonPublic);
        if (property == null || !typeof(IDictionary).IsAssignableFrom(property.PropertyType))
        {
            throw new NotSupportedException("This version of YARP is incompatible with the current version of ASP.NET Core.");
        }
        _policyMap = (property.GetValue(_outputCacheOptions, null) as IDictionary) ?? new Dictionary<string, object>();
    }

    public ValueTask<object?> GetPolicyAsync(string policyName)
    {
        return ValueTask.FromResult(_policyMap[policyName]);
    }
}

View on GitHub (pinned to bd11867bee)

Solutions

  1. Align YARP and ASP.NET Core versions — use the YARP release that targets your ASP.NET Core version.
  2. Update the Microsoft.Extensions.Caching.Memory / Microsoft.AspNetCore.OutputCaching packages to match.
  3. If you do not need output-cache integration, avoid configuring OutputCachePolicy on routes to bypass this provider.

Example fix

// before — mismatched versions in .csproj
<PackageReference Include="Yarp.ReverseProxy" Version="2.0.0" />
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="7.0.0" />
// after — aligned versions
<PackageReference Include="Yarp.ReverseProxy" Version="2.1.0" />
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="8.0.0" />
Defensive patterns

Strategy: validation

Validate before calling

// Verify compatibility at startup before relying on output-cache policy lookup
var prop = typeof(OutputCacheOptions).GetProperty("NamedPolicies", BindingFlags.Instance | BindingFlags.NonPublic);
if (property is null || !typeof(IDictionary).IsAssignableFrom(property.PropertyType))
    logger.LogWarning("YARP/ASP.NET Core output-cache incompatibility detected");

Type guard

// n/a — runtime reflection check

Try / catch

try { services.AddSingleton<YarpOutputCachePolicyProvider>(); }
catch (NotSupportedException ex) when (ex.Message.Contains("incompatible"))
{ logger.LogCritical(ex, "Upgrade YARP or ASP.NET Core to compatible versions."); throw; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13). Data as JSON: /api/errors/73f43f81cf23dcbe. Report an issue: GitHub.