Open Closed

DateOnly? and DateTime? return validation errors when null or empty #9736


User avatar
0
auxo-devsu created
  • Exception message and full stack trace: 2025-08-05T23:50:36.430962367Z [23:50:36 WRN] ---------- RemoteServiceErrorInfo ---------- 2025-08-05T23:50:36.431125991Z { 2025-08-05T23:50:36.431141350Z "code": null, 2025-08-05T23:50:36.431151119Z "message": "Your request is not valid!", 2025-08-05T23:50:36.431182437Z "details": "The following errors were detected during validation.\n - inspectionDate is null!\n", 2025-08-05T23:50:36.431201413Z "data": null, 2025-08-05T23:50:36.431208807Z "validationErrors": [ 2025-08-05T23:50:36.431215269Z { 2025-08-05T23:50:36.431221992Z "message": "inspectionDate is null!", 2025-08-05T23:50:36.431228564Z "members": [ 2025-08-05T23:50:36.431235157Z "inspectionDate" 2025-08-05T23:50:36.431241849Z ] 2025-08-05T23:50:36.431267207Z } 2025-08-05T23:50:36.431274380Z ] 2025-08-05T23:50:36.431281424Z } 2025-08-05T23:50:36.431287555Z 2025-08-05T23:50:36.432740667Z [23:50:36 WRN] Method arguments are not valid! See ValidationErrors for details. 2025-08-05T23:50:36.432766135Z Volo.Abp.Validation.AbpValidationException: Method arguments are not valid! See ValidationErrors for details. 2025-08-05T23:50:36.432775894Z at Volo.Abp.Validation.MethodInvocationValidator.ThrowValidationError(MethodInvocationValidationContext context) 2025-08-05T23:50:36.432782175Z at Volo.Abp.Validation.MethodInvocationValidator.ValidateAsync(MethodInvocationValidationContext context) 2025-08-05T23:50:36.432821569Z at Volo.Abp.Validation.ValidationInterceptor.ValidateAsync(IAbpMethodInvocation invocation) 2025-08-05T23:50:36.432829143Z at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation) 2025-08-05T23:50:36.432836738Z at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) 2025-08-05T23:50:36.432843781Z at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) 2025-08-05T23:50:36.432850464Z at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() 2025-08-05T23:50:36.432857146Z at Volo.Abp.Auditing.AuditingInterceptor.ProceedByLoggingAsync(IAbpMethodInvocation invocation, AbpAuditingOptions options, IAuditingHelper auditingHelper, IAuditLogScope auditLogScope) 2025-08-05T23:50:36.432863588Z at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation) 2025-08-05T23:50:36.432869710Z at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) 2025-08-05T23:50:36.432875882Z at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) 2025-08-05T23:50:36.432882364Z at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() 2025-08-05T23:50:36.432895719Z at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) 2025-08-05T23:50:36.432901710Z at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) 2025-08-05T23:50:36.432908002Z at PartnerHub.Vic.VehicleController.GetAsync(String plateId, Nullable1 inspectionDate, String vin, String chassisNumber) in /home/runner/work/Simon-BE/Simon-BE/src/partner-hub/PartnerHub.HttpApi/Controllers/Vic/VehicleController.cs:line 26 2025-08-05T23:50:36.432914845Z at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) 2025-08-05T23:50:36.432920806Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask1 actionResultValueTask) 2025-08-05T23:50:36.432927038Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) 2025-08-05T23:50:36.432941685Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) 2025-08-05T23:50:36.432947957Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) 2025-08-05T23:50:36.432954118Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() 2025-08-05T23:50:36.432960510Z --- End of stack trace from previous location --- 2025-08-05T23:50:36.432966712Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) 2025-08-05T23:50:36.439023233Z [23:50:36 WRN] There are 1 validation errors: 2025-08-05T23:50:36.439112948Z inspectionDate is null! (inspectionDate)

  • Steps to reproduce the issue:

  • Use DateOnly? (nullable) as part of a GET request

  • Keep that value as null or empty

  • ABP validates that expecting it to have a value


10 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • In ABP Framework, input parameters for application service methods and controllers are automatically validated using data annotation attributes and custom validation logic. By default, nullable types like DateOnly? or DateTime? should not trigger a validation error when their value is null, unless you have applied a [Required] attribute or custom validation that enforces a value.

    • If you are seeing a validation error such as "inspectionDate is null!" when passing null for a DateOnly? or DateTime? parameter, it is likely that:

      1. The parameter or its DTO property is decorated with the [Required] attribute, or
      2. There is a custom validation rule (e.g., IValidatableObject, custom validator, or manual check) that throws an error when the value is null.
    • To resolve this:

      • Remove the [Required] attribute from the parameter/property if you want to allow null values.
      • Check for any custom validation logic in your DTOs, controllers, or services that may be enforcing non-null values.
      • If you want to allow nulls, ensure your method signature uses DateOnly? or DateTime? (nullable) and that no validation rule requires a value.

    Example:

    public async Task<IActionResult> GetAsync(string plateId, DateOnly? inspectionDate, string vin, string chassisNumber)
    {
        // inspectionDate can be null here
    }
    

    If you have a DTO:

    public class MyDto
    {
        // Do NOT add [Required] if you want to allow nulls
        public DateOnly? InspectionDate { get; set; }
    }
    
    • If you are not using [Required] and still see this error, check for custom validation logic in your codebase that may be enforcing this rule.

    Sources:


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    auxo-devsu created

    There's no [Required] attribute or custom logic enforcing it.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Could you please share the code that reproduces the issue?

    Thanks

  • User Avatar
    0
    auxo-devsu created

    I provided an example on my request, but if you have any API projects on ABP, as I assume you do, please do the following:

    public async Task<IActionResult> GetSomethingByDateAsync([FromQuery] DateOnly? date)
    {
        yourAppService.GetSomethingByDateAsync(date); // Before it reaches the AppService the ABP Validations will throw an exception when date is null despite being a nullable DateOnly
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    It will best if you can share a template project.

    Thanks.

  • User Avatar
    0
    auxo-devsu created

    This makes me feel that you either didn't understand what I said or that you don't want to try by yourself. For most of your customers, we have real IP in our projects, and a lot of them would be large enough not to be shared here.It's a job in itself to create a new project just to share it here.

    public async Task<IActionResult> GetSomethingByDateAsync([FromQuery] DateOnly? date)
    {
        yourAppService.GetSomethingByDateAsync(date); // Before it reaches the AppService the ABP Validations will throw an exception when date is null despite being a nullable DateOnly
    }
    

    If you look at your code, there's no App Service dependency accepting the DateOnly. Instead of having a Redirect create an AppService that accepts DateOnly? and you will see what I described above.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Try to add this to your project, and I will fix it in the framework.

    Thanks

    using System.Reflection;
    using System.Threading.Tasks;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.Reflection;
    using Volo.Abp.Validation;
    
    namespace MyCompanyName.MyProjectName.Web;
    
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(MethodInvocationValidator), typeof(IMethodInvocationValidator))]
    public class MyMethodInvocationValidator : MethodInvocationValidator
    {
        private readonly IObjectValidator _objectValidator;
    
        public MyMethodInvocationValidator(IObjectValidator objectValidator)
            : base(objectValidator)
        {
            _objectValidator = objectValidator;
        }
        
        protected override async Task AddMethodParameterValidationErrorsAsync(IAbpValidationResult context, ParameterInfo parameterInfo, object parameterValue)
        {
            var allowNulls = parameterInfo.IsOptional ||
                             parameterInfo.HasDefaultValue ||
                             parameterInfo.IsOut ||
                             TypeHelper.IsNullable(parameterInfo.ParameterType) ||
                             TypeHelper.IsPrimitiveExtended(parameterInfo.ParameterType, includeEnums: true);
    
            context.Errors.AddRange(
                 await _objectValidator.GetErrorsAsync(
                    parameterValue,
                    parameterInfo.Name,
                    allowNulls
                )
            );
        }
    }
    
    
  • User Avatar
    0
    alper created
    Support Team Director

    we cannot help you if you don't cooperate with us for your problem. In this post, he's showing that he can successfully use DateOnly?

  • User Avatar
    0
    auxo-devsu created

    @alper I have been a customer for years, and I'm sure if anything, I'm cooperating with the framework by sharing my challenge here. There are multiple ways of getting around that, and bringing this to attention is the right call. If you have read my message and the response I provided, you would see nothing but cooperation.

    @mailiming Thanks for the acknowledgement and for having a closer look at the problem I described. That fix should resolve the issue for me and any other ABP users looking to do that in the future. Much appreciated!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks @auxo-devsu

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 01, 2025, 08:37