Exception in OnInitalizedAsync

Hello,

I use the dropdow like this :

        <SfDropDownList @ref=@configurations TValue="Guid" TItem="OdqConfigurationModel" @bind-Value="@currentId" DataSource="@cachedConfigurations" EnablePersistence="true" Width="150px">
            <DropDownListFieldSettings Text="Nom" Value="Id" />
            <DropDownListEvents ValueChange="OnValueChanged" TValue="Guid" TItem="string" />
        </SfDropDownList>


I've got the exception :

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.DropDownListEvents`2.<OnInitializedAsync>d__60[[System.Guid, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()


3 Replies 1 reply marked as answer

JM Jeyanth Muthu Pratheeban Sankara Subramanian Syncfusion Team October 13, 2020 11:49 AM UTC

Hi Brice, 

Greetings from Syncfusion support. 

We have checked the error message and the code snippet provided. Based on the provided information, we found that you have used TItem for SfDropdownList tag helper as OdqConfigurationModel and TValue for DropDownListEvents  taghelper as string type. We would like to know you that both the tags should have the same type of item to be bound for TItem attribute. We also would like to know you that type of Value configured in DropDownListFieldSettings should be same as that of TValue type. For instance, Value in DropDownListFieldSettings type as string, then TValue should be string. Please find the sample below for your reference.


 
<SfDropDownList @ref=@configurations TValue="Guid" TItem="OdqConfigurationModel" @bind-Value="@currentId" DataSource="@cachedConfigurations"  Width="150px"> 
    <DropDownListFieldSettings Text="Nom" Value="Nom" /> 
    <DropDownListEvents ValueChange="OnValueChanged" TValue="Guid" TItem="OdqConfigurationModel" /> 
</SfDropDownList> 



 
@code { 
    public Guid currentId { get; set; } = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00"); 
    public SfDropDownList<Guid, OdqConfigurationModel> configurations; 
    public class OdqConfigurationModel 
    { 
        public Guid Nom { get; set; } 
        public string Id { get; set; } 
    } 
 
    public List<OdqConfigurationModel> cachedConfigurations = new List<OdqConfigurationModel>() 
    { 
        new OdqConfigurationModel(){Nom = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00")Id = "1"}, 
        new OdqConfigurationModel(){Nom = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF01")Id = "2"}, 
        new OdqConfigurationModel(){Nom = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF02")Id = "3"}, 
        new OdqConfigurationModel(){Nom = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00")Id = "4"} 
 
    }; 
    public void OnValueChanged(ChangeEventArgs<Guid, OdqConfigurationModel> args) 
    { 
 
    } 
 
} 

  
Kindly check the sample and get back to us if you need any further assistance on this.

Regards, 
Jeyanth. 



BF Brice FROMENTIN October 15, 2020 09:52 AM UTC

Thanks for your help, I fix the errors on my side and was able to reproduce the issue on your sample. If you specify "EnablePersistence" the bug raises.

@page "/"

@using Syncfusion.Blazor.DropDowns;

<SfDropDownList @ref=@configurations TValue="Guid" TItem="OdqConfigurationModel" @bind-Value="@currentId" DataSource="@cachedConfigurations" EnablePersistence="true" Width="150px">
    <DropDownListFieldSettings Text="Nom" Value="Id" />
    <DropDownListEvents ValueChange="OnValueChanged" TValue="Guid" TItem="OdqConfigurationModel" />
</SfDropDownList>

@code
{
    public Guid currentId { get; set; } = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF01");
    public SfDropDownList<Guid, OdqConfigurationModel> configurations;
    public class OdqConfigurationModel
    {
        public Guid Id { get; set; }
        public string Nom { get; set; }
    }

    public List<OdqConfigurationModel> cachedConfigurations = new List<OdqConfigurationModel>()
    {
        new OdqConfigurationModel {Id = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF01"), Nom = "1"},
        new OdqConfigurationModel {Id = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF02"), Nom = "2"},
        new OdqConfigurationModel {Id = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF03"), Nom = "3"},
        new OdqConfigurationModel {Id = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF04"), Nom = "4"}
    };

    public void OnValueChanged(ChangeEventArgs<Guid, OdqConfigurationModel> args)
    {

    }
}

<style>
    .name {
    margin-right: 20px;
    }
</style>


JM Jeyanth Muthu Pratheeban Sankara Subramanian Syncfusion Team October 16, 2020 10:00 AM UTC

Hello Brice, 

Thanks for your explanation. 

Currently we are encountering the issue with enabling EnablePersistence property and we considered this as a defect in our end. The fix for the issue will be included in the patch release which is expected to be rolled out on  October 27th 2020. We appreciate your patience until then. Please find the feedback link below for your reference. 


However you can working around this issue by setting TValue as Guid? . Please find the sample below. 

<SfDropDownList @ref=@configurations TValue="Guid?" ID="auto" TItem="OdqConfigurationModel" @bind-Value="@currentId" DataSource="@cachedConfigurations" EnablePersistence="true" Width="150px"> 
    <DropDownListFieldSettings Text="Nom" Value="Id" /> 
    <DropDownListEvents ValueChange="OnValueChanged" TValue="Guid?" TItem="OdqConfigurationModel" /> 
</SfDropDownList> 
 
@code 
{ 
    public GuidcurrentId { get; set; } = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF01"); 
    public SfDropDownList<Guid?OdqConfigurationModelconfigurations; 
    public class OdqConfigurationModel 
    { 
        public Guid Id { get; set; } 
        public string Nom { get; set; } 
    } 
 
    public List<OdqConfigurationModelcachedConfigurations = new List<OdqConfigurationModel>() 
{ 
        new OdqConfigurationModel {Id = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF01")Nom = "1"}, 
        new OdqConfigurationModel {Id = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF02")Nom = "2"}, 
        new OdqConfigurationModel {Id = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF03")Nom = "3"}, 
        new OdqConfigurationModel {Id = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF04")Nom = "4"} 
    }; 
 
    public void OnValueChanged(ChangeEventArgs<Guid?, OdqConfigurationModel> args) 
    { 
 
    } 
} 

 


Regards, 
Jeyanth. 


Marked as answer
Loader.
Up arrow icon