We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

NullReferenceException when populating in OnInitializedAsync

Thread ID:

Created:

Updated:

Platform:

Replies:

150582 Jan 12,2020 03:30 PM UTC Mar 23,2020 04:59 AM UTC Blazor 9
loading
Tags: Chips
axl
Asked On January 12, 2020 03:31 PM UTC

Hi,

if chips added at runtime within OnInitializedAsync() and an awaited async call performs within the methodblock an execption is trown:

NullReferenceException: Object reference not set to an instance of an object.
Syncfusion.EJ2.Blazor.Buttons.ChipListComponent.initGenerate(int i, ChipListChip Chip)

html:
     
            @foreach(ChipCollection currentData in ChipData){
               
            }
     
     

c#:
protected override async Task OnInitializedAsync ()
{
await base.OnInitializedAsync();

await Task.Delay( 2500 ); // comment out to get it to work, comment in to force an excpetion

ChipData.Add(new ChipCollection
{
text = "Jenifer",
enabled = true
});
}


Examplecode:
  • load this by syncfusion provided code example from this thread (https://www.syncfusion.com/forums/149053/bind-chips-to-listlttgt, BlazorApp1-422972851.zip)
  • update Syncfusion.EJ2.Blazor nuget to current version 17.04.42
  • replace c#-code within index.razor with this code. html is untouched
 
After ommenting out 'await Task.Delay( 2500 );' it will run, comment in and the exception is thrown. Of course any other awaited async code like getting json data results in the same exception. The exception is not thrown immediately, but when the method has returned.

Please help me with this problem and also give me a link to the documentation where this behaviour is described and which particular rules apply when using Syncfusion controls from OnInitializedAsync. I'm sure it's written somewhere, but I haven't found it yet...

One more request: it would surely be better to write the sample code with asynchronous method calls (OnInitializedAsync) anyway, since asynchronous processing is preferable.

Anyway, thanks a lot for the support.
Axel.

Shameer Ali Baig Sulaiman Ali Baig [Syncfusion]
Replied On January 13, 2020 10:12 AM UTC

Hi Axel, 
 
Greetings from Syncfusion support. 
 
We have checked your reported query that while using delay() throw some exception. Yes, we are able to reproduce the issue from our end. This issue will occur while sending ChipData value as zero to the component. To resolve your issue, check the condition whether the ChipData value is equal to zero or not. Refer the below code snippet. 

@if(ChipData.Count != 0) { 
<EjsChipList EnableDelete="true"> 
    <ChipCollection> 
        @foreach (ChipCollection currentData in ChipData) 
        { 
        } 
    </ChipCollection> 
</EjsChipList> 
} 

You can also resolve the issue using another method (onInitialized along with onInitailizedAsync method), you can perform any operations in OnInitialized() method.  
 
Because, onInitialized() method  will be triggered during task.Delay() progress in onInitializedAsync method. Chip component is rendered correctly in your application.  
 
To know more about, refer the below link. 
 
 
We have prepared a sample for your reference. Refer the sample link below. 
 
 
Please let us know, if you have any further assistance on this. 
 
Regards, 
Shameer Ali Baig S. 


axl
Replied On January 18, 2020 09:59 AM UTC

An insightful link and answer. Thank you very much.

Axel.

Shameer Ali Baig Sulaiman Ali Baig [Syncfusion]
Replied On January 20, 2020 06:18 AM UTC

Hi Axel, 
  
Most Welcome. We are happy to hear that the provided solution resolve your reported issue. Please let us know, if you need any further assistance. 
  
Regards, 
Shameer Ali Baig S. 


Mayur
Replied On January 26, 2020 08:41 PM UTC

Hi Axel, 
  
Most Welcome. We are happy to hear that the provided solution resolve your reported issue. Please let us know, if you need any further assistance. 
  
Regards, 
Shameer Ali Baig S. 


Now, if I try to dynamically add, I get the same exception after clicking the button more than once (the first click adds without any issues). 
Following is the code (the markup part is exactly the same as given in the code except for addition of one EjsButton which raised OnClick event)

@using Syncfusion.EJ2.Blazor.Buttons
@if (ChipData.Count != 0)
{
   
       
            @foreach (ChipCollection currentData in ChipData)
            {
               
            }
       
   
}

add chips

@code{

    public List ChipData = new List();
    public class ChipCollection
    {
        public string text { get; set; }
        public bool enabled { get; set; }
    }
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        //await Task.Delay(2000);
        ChipData.Add(new ChipCollection
        {
            text = "Jenifer",
            enabled = true
        });
        ChipData.Add(new ChipCollection
        {
            text = "Amenda",
            enabled = true
        });
        ChipData.Add(new ChipCollection
        {
            text = "Isabella",
            enabled = true
        });
        ChipData.Add(new ChipCollection
        {
            text = "James",
            enabled = true
        });

    }

    public void OnClick()
    {
        ChipData.Add(new ChipCollection
        {
            text = "James",
            enabled = true
        });
    }
}




Sowmiya Padmanaban [Syncfusion]
Replied On January 27, 2020 12:33 PM UTC

Hi Axel,  
 
Greetings from Syncfusion support. 
 
We have checked your reported query to adding more than two items dynamically. We are able to reproduce the issue from our end. We might consider this as a bug from our end. This bug fix will be included in our Volume 4 SP1 Release which is expected to be released at the end of January. Please be patience, until then. 
 
Please let us know, if you need any further assistance on this. 
 
Regards,  
Sowmiya.P 


axl
Replied On January 31, 2020 10:54 AM UTC

Hi Axel,  
 
Greetings from Syncfusion support. 
 
We have checked your reported query to adding more than two items dynamically. We are able to reproduce the issue from our end. We might consider this as a bug from our end. This bug fix will be included in our Volume 4 SP1 Release which is expected to be released at the end of January. Please be patience, until then. 
 
Please let us know, if you need any further assistance on this. 
 
Regards,  
Sowmiya.P 


I think you wanted to answer Mayur and not me ;)

Shameer Ali Baig Sulaiman Ali Baig [Syncfusion]
Replied On February 3, 2020 08:51 AM UTC

Hi Mayur,  
  
We are glad to announce that our Essential Studio 2019 Volume 4 Service Pack release v17.4.0.46 is rolled out and is available for download under the following link.  
  
   
In this release, we have included a fix for “Dynamically add more than one chip items to Chip component”.  
   
For your reference, we have prepared a simple sample. Refer the sample link below.  
  
   
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.  
  
Regards,  
Shameer Ali Baig S. 


shahr
Replied On March 20, 2020 09:06 PM UTC

Hi . i just want to work with your component. The first page I made gives this error. I only used the text box on my page.
Please help me


Shameer Ali Baig Sulaiman Ali Baig [Syncfusion]
Replied On March 23, 2020 04:59 AM UTC

Hi Shahr, 
 
Greetings from Syncfusion support. 
 
We have checked your expected requirement. We have prepared a simple Blazor application with Blazor SF Textboxes to meet your expectation.  
 
Note: we have prepared this sample with latest Syncfusion Blazor version v18.1.36, in which have made major name changes to Syncfusion Blazor components. To know more about that, please check out the following release notes section. 
 
 
Please, download the Blazor server-side application with SF Textboxes from the following link. 
 
Please, let us know if you need any further assistance. 
 
Regards, 
Shameer Ali Baig S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon