错误概要
Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter[webapi.aot.model.GenicQueryCall,System.Int32](System.Func2[webapi.aot.model.GenicQueryCall, System.Int32],System.Object)' is missing native code. MethodInfo.MakeGenericMethod() is not compatible with AOT compilation.
详细
System.NotSupportedException: 'Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter[webapi.aot.model.GenicQueryCall,System.Int32](System.Func2[webapi.aot.model.GenicQueryCall, System.Int32],System.Object)' is missing native code. MethodInfo.MakeGenericMethod() is not compatible with AOT compilation. Inspect and fix AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility
at System.Reflection.Runtime.MethodInfos.RuntimeNamedMethodInfo1.GetUncachedMethodInvoker(RuntimeTypeInfo[], MemberInfo) + 0x2f
at System.Reflection.Runtime.MethodInfos.RuntimeNamedMethodInfo1.MakeGenericMethod(Type[]) + 0x18e
at Microsoft.Extensions.Internal.PropertyHelper.MakeFastPropertyGetter(Type openGenericDelegateType, MethodInfo propertyGetMethod, MethodInfo openGenericWrapperMethod) + 0xb6
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.CreateSinglePropertyDetails(ModelMetadataIdentity propertyKey, PropertyHelper propertyHelper) + 0xec
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.CreatePropertyDetails(ModelMetadataIdentity key) + 0xc7
at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.G
声明的参数如下:
public string GenericExecCall(GenericCall GenicCall)
{
试过编写rd.xml
<Assembly Name="webapi">
<Type Name="webapi.aot.model.KeyValue" Dynamic="Required All" />
</Assembly>
无法解决
也试过源生成
[JsonSerializable(typeof(GenericParamCall))]
[JsonSerializable(typeof(System.Collections.Generic.Dictionary<GenericParamCall, System.Int32>))]
[JsonSerializable(typeof(Newtonsoft.Json.Linq.JObject))]
internal partial class MyJsonContext : JsonSerializerContext
{
依然无法解决,我的想法是不让她触发CallNullSafePropertyGetter ,也就是给参数设置默认值,结果并没有卵用
Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter所属dll不知道,试过框架 App作为 dll就去过滤Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter[webapi.aot.model.GenericParamCall,System.Int32]
如
<Assembly Name="到底哪个dll???">
<Type Name="Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter[webapi.aot.model.GenericCall,System.Int32]" Dynamic="Required All" />
<Type Name="Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter[webapi.aot.model.GenericParamCall,System.Int32]" Dynamic="Required All" />
</Assembly>
问题是不知道属于哪个dll的。
![](https://img.haomeiwen.com/i2815884/cd91e1ada34b5edc.png)
目前能用的是作为接口返回值是ok的,这个时候是不会报错,唯独 作为参数声明不行。
dotnet/src/aspnetcore/src/Shared/PropertyHelper/PropertyHelper.cs at 89eaa42dd7c95b0a1bf62dbaec4ee08b094108d0 · dotnet/dotnet (github.com)
网友评论