Starts in:
1 DAY
23 HRS
34 MIN
57 SEC
Starts in:
1 D
23 H
34 M
57 S
Open Closed

Error on HttpApi controller manual #2902


User avatar
0
andmattia created
  • ABP Framework version: v5.2.0
  • UI type: Angular
  • DB provider: MongoDB
  • Tiered (MVC) or Identity Server Separated (Angular): no Tired / IS separeted
  • Exception message and stack trace:
[Area(DynamicTemplateRemoteServiceConsts.ModuleName)]
[RemoteService(Name = DynamicTemplateRemoteServiceConsts.RemoteServiceName)]
[Route("api/custom/layout-template")]
public class LayoutTemplateController : DynamicTemplateController, ILayoutTemplateAppService
{
    protected ILayoutTemplateAppService LayoutTemplateAppService { get; }

    public LayoutTemplateController(ILayoutTemplateAppService layoutTemplateAppService)
    {
        LayoutTemplateAppService = layoutTemplateAppService;
    }

    [HttpPost]
    [Route("give-layout-templates")]
    public Task<PagedResultDto<LayoutTemplateDto>> GiveLayoutTemplates(GetLayoutTemplateInput input)
    {
        return LayoutTemplateAppService.GiveLayoutTemplates(input);
    }

This generate an error

2022-04-13 12:21:09.582 +02:00 [INF] Executing action method Dm.DynamicTemplate.LayoutTemplateController.ProvaInput (Dm.DynamicTemplate.HttpApi) - Validation state: "Valid"
2022-04-13 12:21:11.093 +02:00 [ERR] ---------- RemoteServiceErrorInfo ----------
{
  "code": null,
  "message": "An internal error occurred during your request!",
  "details": null,
  "data": {},
  "validationErrors": null
}

2022-04-13 12:21:11.093 +02:00 [ERR] Property accessor 'DeclaringMethod' on object 'System.RuntimeType' threw the following exception:'Method may only be called on a Type for which Type.IsGenericParameter is true.'
System.Reflection.TargetInvocationException: Property accessor 'DeclaringMethod' on object 'System.RuntimeType' threw the following exception:'Method may only be called on a Type for which Type.IsGenericParameter is true.'
 ---> System.InvalidOperationException: Method may only be called on a Type for which Type.IsGenericParameter is true.
   at System.RuntimeType.get_DeclaringMethod()
   --- End of inner exception stack trace ---

if I use the code below in Http APi (importing Application Module or in Host Module) the API works fine (I try in 5.1.4 and 5.2.0) this happen only with this input object. The inpunt object exted a class that extend PagedAndSortedResultRequestDto. Internally I have an array object the same type.

public class Filter {
    public string Name {get;set;}
    public Filter[] Filters {get;set;}
    }

        Configure<AbpAspNetCoreMvcOptions>(options =>
        {
            options.ConventionalControllers.Create(typeof(DynamicTemplateApplicationModule).Assembly, opts =>
            {
                opts.RootPath = "custom/";
            });
        });```

6 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please share the full error logs.

  • User Avatar
    0
    andmattia created

    Hi

    this is the full stack log for this issue

    2022-04-13 12:21:09.582 +02:00 [INF] Executing action method Dm.DynamicTemplate.LayoutTemplateController.ProvaInput (Dm.DynamicTemplate.HttpApi) - Validation state: "Valid"
    2022-04-13 12:21:11.093 +02:00 [ERR] ---------- RemoteServiceErrorInfo ----------
    {
      "code": null,
      "message": "An internal error occurred during your request!",
      "details": null,
      "data": {},
      "validationErrors": null
    }
    
    2022-04-13 12:21:11.093 +02:00 [ERR] Property accessor 'DeclaringMethod' on object 'System.RuntimeType' threw the following exception:'Method may only be called on a Type for which Type.IsGenericParameter is true.'
    System.Reflection.TargetInvocationException: Property accessor 'DeclaringMethod' on object 'System.RuntimeType' threw the following exception:'Method may only be called on a Type for which Type.IsGenericParameter is true.'
     ---> System.InvalidOperationException: Method may only be called on a Type for which Type.IsGenericParameter is true.
       at System.RuntimeType.get_DeclaringMethod()
       --- End of inner exception stack trace ---
       at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
       at Volo.Abp.Validation.DataAnnotationObjectValidationContributor.ValidateObjectRecursively(List`1 errors, Object validatingObject, Int32 currentDepth)
       at Volo.Abp.Validation.DataAnnotationObjectValidationContributor.ValidateObjectRecursively(List`1 errors, Object validatingObject, Int32 currentDepth)
       at Volo.Abp.Validation.DataAnnotationObjectValidationContributor.AddErrorsAsync(ObjectValidationContext context)
       at Volo.Abp.Validation.ObjectValidator.GetErrorsAsync(Object validatingObject, String name, Boolean allowNull)
       at Volo.Abp.Validation.MethodInvocationValidator.AddMethodParameterValidationErrorsAsync(IAbpValidationResult context, ParameterInfo parameterInfo, Object parameterValue)
       at Volo.Abp.Validation.MethodInvocationValidator.AddMethodParameterValidationErrorsAsync(MethodInvocationValidationContext context)
       at Volo.Abp.Validation.MethodInvocationValidator.ValidateAsync(MethodInvocationValidationContext context)
       at Volo.Abp.Validation.ValidationInterceptor.ValidateAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync()
       at Volo.Abp.Auditing.AuditingInterceptor.ProceedByLoggingAsync(IAbpMethodInvocation invocation, IAuditingHelper auditingHelper, IAuditLogScope auditLogScope)
       at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo)
       at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync()
       at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
       at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
       at lambda_method1367(Closure , Object )
       at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
    --- End of stack trace from previous location ---
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please share the class of GetLayoutTemplateInput

  • User Avatar
    0
    andmattia created

    Hi

    this is the code

    public class GetLayoutTemplateInput : CustomPagedAndSortedInputDto
    {
        public GetLayoutTemplateInput() : base()
        {
            GridDefinitionType = typeof(LayoutTemplateDto);
        }
        public string Filter { get; set; }
    }
    
    
        [Serializable]
        public class CustomPagedAndSortedInputDto : PagedAndSortedResultRequestDto, IFilteredResultRequest
        {
            public FilterDto[] Filters { get; set; }
            public Type GridDefinitionType { get; set; }
    
            public virtual string GetDefaultSorting()
            {
                ...
            }
    
            public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
            {
                //Set default sorting
                ...
                
             }
        }
    }
    
    public class FilterDto : IFilter
    {
        public string Field { get; set; }
        public string Operator { get; set; }
        public object Value { get; set; }
        public string GetFullObject()
        {
            var q = this.Field.UppercaseFirst();
    
            if (!this.BaseObject.IsNullOrWhiteSpace())
            {
                ...
            }
    
            return q;
        }
    
        public string BaseObject { get; set; }
        public string PropertyName { get; set; }
        public string Logic { get; set; }
        public IFilter[] Filters { get; set; }
    }
    
    
  • User Avatar
    1
    maliming created
    Support Team Fullstack Developer

    hi

    we don't recommend using Type in dto. Replace it or add DisableValidationAttribute to this property.

    public Type GridDefinitionType { get; set; }
    
  • User Avatar
    0
    andmattia created

    Hi @maliming

    thanks for the support.

    I try to remove with DisableValidationAttribute and it works!

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06