Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Arjan H. 226 posts 463 karma points c-trib
    Jan 26, 2023 @ 10:44
    Arjan H.
    0

    System.InvalidOperationException error when Date Picker is set to today or in the past

    I have an entity with a public DateTime? WorkshopDate { get; set; } field. And I'm using a Date Picker for this field in the editor. I get the following error when trying to save the entity with the Date Picker set to today or in the past:

    An error occurred

    property with alias: WorkshopDate was not found

    Exception Details

    System.InvalidOperationException, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e: property with alias: WorkshopDate was not found

    Stacktrace

    at Konstrukt.Web.WebApi.Validation.KonstruktEntityValidator.ValidateProperties(ModelStateDictionary modelState, KonstruktEntityPostModel postModel, KonstruktEditorFieldConfig[] configProps)
       at Konstrukt.Web.WebApi.Validation.KonstruktEntityValidator.Validate(KonstruktCollectionConfig collectionConfig, ModelStateDictionary modelState, KonstruktEntityPostModel postModel, Object entity, KonstruktEditorMode editorMode)
       at Konstrukt.Web.Controllers.Api.KonstruktApiController.SaveEntity(KonstruktEntityPostModel postModel)
       at lambda_method269(Closure , Object , Object[] )
       at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
    --- End of stack trace from previous location ---
       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)
    

    Saving works fine when I set a date in the future. I have not added any validation to the field.

  • Arjan H. 226 posts 463 karma points c-trib
    Jan 26, 2023 @ 10:52
    Arjan H.
    0

    Hmm, I don't have this issue on another collection with DateTime? fields and a Date Picker. So I must be doing something wrong with this particular collection, but I'm not seeing it. Any pointers would be appreciated.

  • Arjan H. 226 posts 463 karma points c-trib
    Jan 26, 2023 @ 11:03
    Arjan H.
    100

    I found the issue. I had a computed IsLocked field on the entite:

    public bool IsLocked => DateTime.Now >= WorkshopDate;

    And I used the following method on the FieldsetConfig:

    .SetVisibility(ctx => ((KonstruktWorkshop?)ctx.Source)?.IsLocked != true)

    So when setting the WorkshopDate to a date in the past this flipped the IsLocked state and somehow causes an issue in Konstrukt when saving the entity.

Please Sign in or register to post replies

Write your reply to:

Draft