美文网首页
AOT编译missing native code. Method

AOT编译missing native code. Method

作者: 吉凶以情迁 | 来源:发表于2023-04-10 09:54 被阅读0次
        Connection id "0HMPQ5RUFQ1EQ", Request id "0HMPQ5RUFQ1EQ:00000001": An unhandled exception was thrown by the application.
          System.NotSupportedException: 'Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter[webapi_mes.api.push.MyInformation,System.Int32](System.Func`2[webapi_mes.api.push.MyInformation, 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.RuntimeNamedMethodInfo`1.GetUncachedMethodInvoker(RuntimeTypeInfo[], MemberInfo) + 0x2f
             at System.Reflection.Runtime.MethodInfos.RuntimeNamedMethodInfo`1.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.GetMetadataForProperties(Type modelType) + 0xa9
             at Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Properties() + 0x61
             at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexObjectModelBinderProvider.GetBinder(ModelBinderProviderContext context) + 0xe7
             at Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderFactory.CreateBinderCoreUncached(ModelBinderFactory.DefaultModelBinderProviderContext providerContext, Object token) + 0x12f
             at Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderFactory.CreateBinder(ModelBinderFactoryContext context) + 0x88
             at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.GetParameterBindingInfo(IModelBinderFactory modelBinderFactory, IModelMetadataProvider modelMetadataProvider, ControllerActionDescriptor actionDescriptor) + 0x131
             at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.CreateBinderDelegate(ParameterBinder parameterBinder, IModelBinderFactory modelBinderFactory, IModelMetadataProvider modelMetadataProvider, ControllerActionDescriptor actionDescriptor, MvcOptions mvcOptions) + 0x71
             at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvokerCache.GetCachedResult(ControllerContext controllerContext) + 0xbc
             at Microsoft.AspNetCore.Mvc.Routing.ControllerRequestDelegateFactory.<>c__DisplayClass12_0.<CreateRequestDelegate>b__0(HttpContext context) + 0x18f
             at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext) + 0x1ad
          --- End of stack trace from previous location ---
             at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
             at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42
             at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.<Invoke>d__9.MoveNext() + 0x382
          --- End of stack trace from previous location ---
             at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x20
             at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xb6
    

    原因是因为有一个方法叫 public String XXX([FromForm] MyInformation information ){}

    这个会用反射实现, 但是aot不支持这.
    解决方法就是不用这个了,这样更香
    假设MyInformation类有 a ,b字段那么改成如下

     public String XXX()
            {
                var a= ParseUtil.parseInt( Request.Form["a"]);
                var b= Request.Form["b"];
    
    
    }
    

    https://learn.microsoft.com/zh-cn/dotnet/core/deploying/native-aot/fixing-warnings

    相关文章

      网友评论

          本文标题:AOT编译missing native code. Method

          本文链接:https://www.haomeiwen.com/subject/diwiddtx.html