"Value cannot be null. (Parameter 'obj')" exception

Hello,
I have a form which contains some validators attached to TextBoxes.
The form also contains a dropbox which does not have any validator. If a user select an item in the dropbox and then submits the form the InvalidSubmit callback is called.

The reason why InvalidSubmit callback is called is that when the form calls EditContext.Validate(); it throws the following exception:

System.ArgumentNullException: Value cannot be null. (Parameter 'obj')
at System.OrdinalCaseSensitiveComparer.GetHashCode(String obj)
at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.GetHashCode()
at System.Collections.Generic.Dictionary2.FindValue(TKey key)
at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value)
at Microsoft.AspNetCore.Components.Forms.ValidationMessageStore.Clear(FieldIdentifier& fieldIdentifier)
at Radzen.Blazor.ValidatorBase.ValidateModel(Object sender, ValidationRequestedEventArgs args)
at Microsoft.AspNetCore.Components.Forms.EditContext.Validate()

Does anybody have an idea would could be the problem?

Here is a minimal self-contained code to reproduce the issue:

@page "/"

@using Radzen;
@using Radzen.Blazor;
@using Microsoft.JSInterop;

@inject IJSRuntime jsRuntime
@inject DialogService myDialogService;

<div class="container bg-light" style="height:30vh">
<RadzenButton Text="Click" Click=@OnCick />
</div>

@code {
private IEnumerable<string> myValues = new List<string>() { "A", "B" };
private IEnumerable<string> myDropBoxData = new List<string>() { "A", "B", "C" };
private string myFormData = "hello";
private RadzenTemplateForm<string> myForm;

private string Value { get; set; }


private async Task OnCick(MouseEventArgs args)
{
   EventCallback<string> submitCallback = EventCallback.Factory.Create<string>(this, OnSubmit);
    EventCallback<FormInvalidSubmitEventArgs> invalidSubmitCallback = EventCallback.Factory.Create<FormInvalidSubmitEventArgs>(this, OnInvalidSubmit);

    await myDialogService.OpenAsync("Hello", x =>
        @<RadzenTemplateForm TItem="string" Data="@myFormData" Submit="@submitCallback" InvalidSubmit="@invalidSubmitCallback"
                             @ref="myForm">
            <div class="row">
                <div class="col">
                    <RadzenTextBox Name="MyTextBox" Value="hello" />
                    <RadzenRequiredValidator Component="MyTextBox" Text="Is required." />
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <RadzenDropDown TValue="string" @bind-Value="@Value" Data="@myDropBoxData" />
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <RadzenButton Text="Submit" ButtonStyle="ButtonStyle.Primary" ButtonType="ButtonType.Submit" />
                </div>
            </div>
         </RadzenTemplateForm>
        );
}

private void OnSubmit(string x)
{
    myDialogService.Close();
}

private void OnInvalidSubmit(FormInvalidSubmitEventArgs args)
{
    try
    {
        myForm.EditContext.Validate();
    }
    catch (Exception err)
    {
        // When you select from the dropbox and then submit this exception occurs.
    }
}

}

Any reason why you are not using @bind-Value for the TextBox? This is what is causing the problem.

BTW you can format your code using markdown. No need to manually escape < and > :slight_smile: - just put it inside ``` block.

Thanks for the response. I just wanted to strip the code to the bare minimum. In my code the problem occurs even if the @bind-Value is used. Hm, but yes in this example when @bind-Value is there it works. So I need to investigate more.

Thanks again for your response. It focused me in right direction.
I have finally found the problem and for the sake of completeness here is the resolution:

I had wrapped the RadzenTextBox into my special text box. The special text box was updating Value after each character as the user was typing. Therefore it was not necessary to @bind-Value - because the value update was happening via the @oninput callback.
The declaration was like this:

<RadzenTextBox Name="@Name" Value="@Value" @oninput="OnInputChanged" />

When the declaration was changed to the following one, it started to work.

<RadzenTextBox Name="@Name" @bind-Value="Value" @oninput="OnInputChanged" />