You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just updated to 2.2.0 and while validating my proxy I get an exception during startup caused by YarpOutputCachePolicyProvider, probably because it is using reflection and it's trying access code that is trimmed away. I'm not even using output caching.
Here's the relevant part of the stack trace:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at System.Reflection.DynamicInvokeInfo..ctor(MethodBase, IntPtr) + 0x314
at Internal.Reflection.Execution.ExecutionEnvironmentImplementation.TryGetMethodInvokeInfo(RuntimeTypeHandle, QMethodDefinition, RuntimeTypeHandle[], MethodBase, MethodSignatureComparer&, CanonicalFormKind) + 0x191
at Internal.Reflection.Execution.ExecutionEnvironmentImplementation.TryGetMethodInvoker(RuntimeTypeHandle, QMethodDefinition, RuntimeTypeHandle[]) + 0xe3
at Internal.Reflection.Core.Execution.ExecutionEnvironment.GetMethodInvoker(RuntimeTypeInfo, QMethodDefinition, RuntimeTypeInfo[], MemberInfo, Exception&) + 0x11e
at System.Reflection.Runtime.MethodInfos.NativeFormat.NativeFormatMethodCommon.GetUncachedMethodInvoker(RuntimeTypeInfo[], MemberInfo, Exception&) + 0x50
at System.Reflection.Runtime.MethodInfos.RuntimeNamedMethodInfo`1.GetUncachedMethodInvoker(RuntimeTypeInfo[], MemberInfo) + 0x1b
at System.Reflection.Runtime.PropertyInfos.RuntimePropertyInfo.GetValue(Object, BindingFlags, Binder, Object[], CultureInfo) + 0x54
at System.Reflection.PropertyInfo.GetValue(Object, Object[]) + 0x1d
at Yarp.ReverseProxy.Configuration.YarpOutputCachePolicyProvider..ctor(IOptions`1 outputCacheOptions) + 0xa7
Publish using PublishAot and attempt to run the application.
Potential fix
You might be able to use the UnsafeAccessorAttribute in .NET 8:
// Define an unsafe accessor[UnsafeAccessor(UnsafeAccessorKind.Method, Name ="get_NamedPolicies")]privatestaticexternDictionary<string,IOutputCachePolicy>?GetNamedPolicies(OutputCacheOptionsc);// Then use it like this_policyMap= GetNamedPolicies(_outputCacheOptions);
For older versions of .NET you need to make sure that the code you are trying to use isn't being trimmed, one way I've successfully done this in my own projects is to create an unused field that references the type with the DynamicallyAccessedMembersAttribute stating what I need to keep.
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]privatestaticreadonly Type keepOutputCacheOptions=typeof(OutputCacheOptions);
Further technical details
Version 2.2.0
Windows
The text was updated successfully, but these errors were encountered:
Thanks for raising the issue. This looks like a Native AOT bug and appears to be fixed in .NET 9.
I think we should add a workaround in YARP to unblock .NET 8 though.
Describe the bug
I just updated to 2.2.0 and while validating my proxy I get an exception during startup caused by
YarpOutputCachePolicyProvider
, probably because it is using reflection and it's trying access code that is trimmed away. I'm not even using output caching.Here's the relevant part of the stack trace:
Here is what I think the offending code is:
reverse-proxy/src/ReverseProxy/Configuration/IYarpOutputCachePolicyProvider.cs
Lines 35 to 37 in 99ce21a
To Reproduce
Publish using
PublishAot
and attempt to run the application.Potential fix
You might be able to use the
UnsafeAccessorAttribute
in .NET 8:For older versions of .NET you need to make sure that the code you are trying to use isn't being trimmed, one way I've successfully done this in my own projects is to create an unused field that references the type with the
DynamicallyAccessedMembersAttribute
stating what I need to keep.Further technical details
The text was updated successfully, but these errors were encountered: