RadzenDatePicker crash when entering invalid time value in the input

When using the RadzenDatePicker if the user types an invalid value for the hour or minute into the input the control crashes upon trying to update the value with the following exception:

blazor.server.js:15 [2020-07-06T10:23:11.964Z] Error: System.NullReferenceException: Object reference not set to an instance of an object.
   at Radzen.Blazor.RadzenDatePicker`1.ParseDate()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

This is the code I'm using:

<RadzenDatePicker ShowTime="true"
                  @bind-Value="DateTime"
                  DateFormat="dd-MM-yyyy HH:mm"
                  HourFormat="24"
                  TValue="DateTime" />

@code {
    private int currentCount = 0;
    private DateTime DateTime { get; set; } = DateTime.Now;
}

I guess it probably doesn't check / sanitize the inputs before attempting to parse? It seems to happen with the date part too.

The issue should be pretty easy to reproduce (just type 99 into the hour part) but I can provide a sample if you need.

Radzen.Blazor 2.10.11 using Blazor Server Side.

Hi @GIDC,

Can you reproduce this problem in our online demo? I couldn't for some reason.

I could not reproduce it in the online demo but looking at the source code there I noticed the TValue generic param is of type DateTime? (nullable DateTime). Changing the type from DateTime to DateTime? does indeed stop the crash (and the input becomes blank so I assume the value is set to null).

So the crash only seems to happen if TValue if of type DateTime which does not allow nulls.

I see what you mean. We will fix that with the next release.

1 Like

The fix has been released.

1 Like