Internal Null Reference Exception in DropDown Component

Hello,

The scenario involves the initialization of an edit form. There are two instances of a custom dropdown component that wrap a SyncfusionDropDown component. On the form. They load there data asynchronously from a server endpoint. Both components have their Value prop set to fields on the model. When the form loads the following null reference exception is thrown:

blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

      Unhandled exception rendering component: Object reference not set to an instance of an object.

System.NullReferenceException: Object reference not set to an instance of an object.

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<UpdateListSelectionAsync>d__597[[System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[SyncfusionIssueSample.Client.Pages.Index.DropDownOption, SyncfusionIssueSample.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<UpdateSelectItemAsync>d__596[[System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[SyncfusionIssueSample.Client.Pages.Index.DropDownOption, SyncfusionIssueSample.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<PropertyChangeAsync>d__534[[System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[SyncfusionIssueSample.Client.Pages.Index.DropDownOption, SyncfusionIssueSample.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<OnParametersSetAsync>d__528[[System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[SyncfusionIssueSample.Client.Pages.Index.DropDownOption, SyncfusionIssueSample.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

Here is the minimal reproduction of the issue:Form code:

@page "/"
@using Syncfusion.Blazor.Inputs;
@using SyncfusionIssueSample.Client.Shared
@using SyncfusionIssueSample.Shared;


@if (editContext != null)
{
    <CustomDropDown Value="model.FieldOne"
                    ValueChanged="(value) => model.FieldOne = value"></CustomDropDown>


    <CustomDropDown Value="model.FieldTwo"
                    ValueChanged="(value) => model.FieldTwo = value"></CustomDropDown>
}


@code {


    public ModelClass? model;


    public EditContext editContext;


    protected override async Task OnInitializedAsync()
    {
        model = new ModelClass();
        model.FieldOne = 1;
        model.FieldTwo = 1;


        editContext = new EditContext(model);
    }


    public class DropDownOption
    {
        public int? Value { get; set; }
        public string DisplayText { get; set; }
    }


    public class ModelClass
    {
        public int? FieldOne { get; set; }
        public int? FieldTwo { get; set; }
    }
}

Custom component code:


@using Syncfusion.Blazor.Inputs;
@using SyncfusionIssueSample.Shared;
@using static SyncfusionIssueSample.Client.Pages.Index;


<SfDropDownList @ref="DropDownList" TItem="DropDownOption" TValue="int?" Value="@Value"
                DataSource="@options" >
    <DropDownListFieldSettings Text="DisplayText" Value="Value"></DropDownListFieldSettings>
    <DropDownListEvents TValue="int?" TItem="DropDownOption" ValueChange="OnValueChange"></DropDownListEvents>
</SfDropDownList>


@code {


    [Parameter] public EventCallback<int?> ValueChanged { get; set; }


    [Parameter]
    public int? Value { get; set; }


    private SfDropDownList<int?, DropDownOption> DropDownList;


    private List<DropDownOption> options = new List<DropDownOption>();


    private bool dataLoaded = false;


    protected override async Task OnParametersSetAsync()
    {
        if (!dataLoaded)
        {
            dataLoaded = true;


            var result = (await GetDropDownOptions()).ToList();


            options = result;
        }
    }


    private async Task OnValueChange(ChangeEventArgs<int?, DropDownOption> args)
    {
        await ValueChanged.InvokeAsync(args.Value);
    }


    public async Task<IEnumerable<DropDownOption>> GetDropDownOptions()
    {
        List<DropDownOption> options = new List<DropDownOption>();
        options.Add(new DropDownOption() { Value = 1, DisplayText = "Option 1" });
        options.Add(new DropDownOption() { Value = 2, DisplayText = "Option 2" });
        options.Add(new DropDownOption() { Value = 3, DisplayText = "Option 3" });


        await Task.Delay(1000);


        return options;
    }
}

The issue seems to involve a combination of the asynchronous data load of the dropdown data, the presence of the change event handlers, and the existence of two or more dropdowns on the form whose field is bound to the form model. It would appear that a value change event is firing, which is causing a state change within the form, and a subsequent on OnParametersSetAsync() call to the other dropdown. However, I don't know how to resolve the issue since it's originating from within the Syncfusion dropdown.

Any guidance here would be much appreciated. I've attached a minimal sandbox reproduction of the issue.

Thank you.


Attachment: SyncfusionIssueSample_1a80584c.zip

7 Replies

KP Kokila Poovendran Syncfusion Team November 6, 2023 09:18 AM UTC

Hi Enoch,


Greeting from Syncfusion support!


We apologize for the inconvenience caused by the issue. We appreciate your effort in sharing the code snippet as well as a runnable sample to reproduce the issue.


We have investigated the issue with the latest package version 23.1.43, and we can confirm that it resolves the problem. The issue you mentioned does not occur in the latest version. To resolve this issue on your end, we recommend upgrading the package to version "23.1.43."


Thank you for your understanding and for bringing this to our attention.


Regards,

Kokila Poovendran.



EN Enoch replied to Kokila Poovendran November 7, 2023 07:13 PM UTC

Hi Kokila,


This resolved my issue and some others as well related to the dropdown. Thank you for your response!



SS Shereen Shajahan Syncfusion Team November 8, 2023 06:24 AM UTC

Hi Enoch,

Glad to know your issue has been resolved. Please get back to us for assistance in the future.

Regards,

Shereen



MW Muhammad WaqasAziz November 17, 2023 08:50 AM UTC

I have the exact same issue


Dotnet 8.0

Syncfusion Blazor version 23.1.44


Cent per Cent Exact behaviour



KP Kokila Poovendran Syncfusion Team November 20, 2023 04:06 PM UTC

Hi Enoch,


We apologize for the inconvenience caused by the issue. We have investigated the issue with the latest package version 24.2.4, and we can confirm that it resolves the problem. The issue you mentioned does not occur in the latest version. To resolve this issue on your end, we recommend upgrading the package to version "24.2.4."



Regards,

Kokila Poovendran.



ST Stephen May 4, 2024 05:00 PM UTC

I am having the same issue with v25.1.41 - Please has this been resolved in version 25? If so, which? See error below.


crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

      Unhandled exception rendering component: Object reference not set to an instance of an object.

System.NullReferenceException: Object reference not set to an instance of an object.

   at ProjectMarks.Frontend.Client.Pages.Project.PActions.<BuildRenderTree>b__0_12(RenderTreeBuilder __builder3)

   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)

   at Syncfusion.Blazor.Grids.GridColumns.<BuildRenderTree>b__23_0(RenderTreeBuilder __builder2)

   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)

   at Microsoft.AspNetCore.Components.CascadingValue`1[[Syncfusion.Blazor.Grids.GridColumns, Syncfusion.Blazor.Grids, Version=25.1.41.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]].Render(RenderTreeBuilder builder)

   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

      Unhandled exception rendering component: Object reference not set to an instance of an object.

System.NullReferenceException: Object reference not set to an instance of an object.

   at ProjectMarks.Frontend.Client.Pages.Project.PActions.<BuildRenderTree>b__0_12(RenderTreeBuilder __builder3)

   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)

   at Syncfusion.Blazor.Grids.GridColumns.<BuildRenderTree>b__23_0(RenderTreeBuilder __builder2)

   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)

   at Microsoft.AspNetCore.Components.CascadingValue`1[[Syncfusion.Blazor.Grids.GridColumns, Syncfusion.Blazor.Grids, Version=25.1.41.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]].Render(RenderTreeBuilder builder)

   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

      Unhandled exception rendering component: Object reference not set to an instance of an object.

System.NullReferenceException: Object reference not set to an instance of an object.

   at ProjectMarks.Frontend.Client.Pages.Project.PActions.<BuildRenderTree>b__0_12(RenderTreeBuilder __builder3)

   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)

   at Syncfusion.Blazor.Grids.GridColumns.<BuildRenderTree>b__23_0(RenderTreeBuilder __builder2)

   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)

   at Microsoft.AspNetCore.Components.CascadingValue`1[[Syncfusion.Blazor.Grids.GridColumns, Syncfusion.Blazor.Grids, Version=25.1.41.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]].Render(RenderTreeBuilder builder)

   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

      Unhandled exception rendering component: Object reference not set to an instance of an object.

System.NullReferenceException: Object reference not set to an instance of an object.

   at ProjectMarks.Frontend.Client.Pages.Project.PActions.<BuildRenderTree>b__0_12(RenderTreeBuilder __builder3)

   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)

   at Syncfusion.Blazor.Grids.GridColumns.<BuildRenderTree>b__23_0(RenderTreeBuilder __builder2)

   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)

   at Microsoft.AspNetCore.Components.CascadingValue`1[[Syncfusion.Blazor.Grids.GridColumns, Syncfusion.Blazor.Grids, Version=25.1.41.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89]].Render(RenderTreeBuilder builder)

   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

The thread '[Thread Destroyed]' (22584) has exited with code 0 (0x0).



PK Priyanka Karthikeyan Syncfusion Team May 6, 2024 12:09 PM UTC

Hi Stephen,

We have diligently worked on ensuring the sample provided in the first update. However, unfortunately, we were unable to reproduce any issues in the latest version 25.1.42. For your reference, please find the attached sample.

To expedite the resolution process and offer you the most accurate assistance, could you kindly consider modifying the shared sample to align it more closely with your specific scenario? Additionally, it would greatly assist us if you could provide detailed steps to replicate the issue on our end.

Your cooperation in this matter is highly valued, and we are committed to ensuring a swift and effective resolution to any challenges you may be facing. Thank you for your time and collaboration.

Regards,

Priyanka K


Attachment: CustomDropDown_d5c041d0.zip

Loader.
Up arrow icon