SfListView is throwing a null reference exception



Hello,

We are getting a strange error in our logs that is originating with a null reference exception in SFListView. See table below (I hope this is still formatted correctly on submit..)
Is there any known issues with SfListView since the last release? Or could you advise how the offending ListView could be identified. (we use them a lot in this application)

Regards
Vincent

type

 

System.NullReferenceException

assembly



Syncfusion.Blazor, Version=18.3.0.42, Culture=neutral, PublicKeyToken=null

method

Syncfusion.Blazor.Lists.SfListView`1.GetLiElementData

outerType

System.NullReferenceException

outerMessage

Object reference not set to an instance of an object.

outerAssembly

Syncfusion.Blazor, Version=18.3.0.42, Culture=neutral, PublicKeyToken=null

outerMethod

Syncfusion.Blazor.Lists.SfListView`1.GetLiElementData

severityLevel

2

details

[{"severityLevel":"Warning","parsedStack":[{"method":"Syncfusion.Blazor.Lists.SfListView`1.GetLiElementData","level":0,"line":0,"assembly":"Syncfusion.Blazor, Version=18.3.0.42, Culture=neutral, PublicKeyToken=null"},{"method":"Syncfusion.Blazor.Lists.SfListView`1+<OnAfterRenderAsync>d__2.MoveNext","level":1,"line":0,"assembly":"Syncfusion.Blazor, Version=18.3.0.42, Culture=neutral, PublicKeyToken=null"},{"method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw","level":2,"line":0,"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"},{"method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess","level":3,"line":0,"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"},{"method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification","level":4,"line":0,"assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"},{"method":"Microsoft.AspNetCore.Components.RenderTree.Renderer+<GetErrorHandledTask>d__42.MoveNext","level":5,"line":0,"assembly":"Microsoft.AspNetCore.Components, Version=3.1.9.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"}],"outerId":"0","message":"Object reference not set to an instance of an object.","type":"System.NullReferenceException","id":"44312721"}]

itemType

exception


7 Replies 1 reply marked as answer

MK Muthukrishnan Kandasamy Syncfusion Team October 23, 2020 12:42 PM UTC

 
Hi Vincent, 
 
Thanks for contacting Syncfusion support. 
 
We have validated your reported problem Blazor ListView component. Were unable to reproduce your reported problem in our end, the List View component renders properly without any issues. We have prepared sample for your convenience, which can be downloaded from the below link. 
 
 
If the issue still persists, please share some additional details. It will be help us to provide you the prompt solution. 
 
      1. Share us the ListView initialization code and its related code.
      2. If possible, share the issue replicated sample or else replicate your reported issue in the attached sample.
      3. Share us the screen recorded video with issue replicating steps.
 
 
Regards, 
Muthukrishnan K 



VM Vincent McCarthy October 26, 2020 07:41 AM UTC

Hello Muthukrishnan

Thanks for the response. Unfortunately, I cant reproduce this issue myself it is something showing up in our logs. I'll try to narrow this issue down and provide a relevant sample. SfListView usually works fine

Regards
Vincent


MK Muthukrishnan Kandasamy Syncfusion Team October 27, 2020 06:14 AM UTC

 
Hi Vincent, 
 
Thanks for the update. 
 
We will wait to hear from you. 
 
Regards, 
Muthukrishnan K 



VM Vincent McCarthy December 4, 2020 08:43 AM UTC

Hello Muthukrishnan

Apologies for the delay in the response, this error has started showing up on the development server again.
I cannot reproduce it locally but the error appears very regular on the page with the following list view implementation


@if (newDashboardViewModel.DashboardTiles != null && newDashboardViewModel.DashboardTiles.Any())
{
 <SfListView ID="DashboardTiles" TValue="@DashboardTileViewModel" DataSource="@newDashboardViewModel.DashboardTiles" ShowCheckBox="true">
                                            <ListViewEvents TValue="@DashboardTileViewModel" Clicked="@((e) => OnTypeInfoSelected(e))" />
                                            <ListViewFieldSettings TValue="@DashboardTileViewModel" Id="@nameof(DashboardTileViewModel.Id)" Text="@nameof(DashboardTileViewModel.DisplayName)" Enabled="@nameof(DashboardTileViewModel.IsEnabled)" IsChecked="@nameof(DashboardTileViewModel.IsSelected)"></ListViewFieldSettings>
                                        </SfListView>
}

  public class DashboardTileViewModel
    {
        public string Id { get; set; }

        public bool IsEnabled { get; set; }

        public bool IsSelected { get; set; }

        public string DisplayName { get; set; }

....

Here is the console error

vendor.js?v=3.44.26.1138:649 [2020-12-04T08:31:20.856Z] Error: System.NullReferenceException: Object reference not set to an instance of an object.
   at Syncfusion.Blazor.Lists.SfListView`1.GetLiElementData(ListElementReference args, Boolean ischecked)
   at Syncfusion.Blazor.Lists.SfListView`1.OnAfterRenderAsync(Boolean firstRender)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

 So I cant understand why the IsSelected property on the model isn't bound to IsChecked on the dev server? The DashboardTileViewModel should always be there by the time the sfList is rendered.


If I build a small sample that has IsChecked set to null or binding to a property that doesnt exist I get the same error. (strangely I can set IsEnabled to any value and I still dont get an error - it would be good if the check functioned like this :) )

Below will reproduce the same error as I get in dev console - just for illustration - maybe it can help explain why a binding in the real version could be sporadically broken.
@using Syncfusion.Blazor.Lists

<!--BROKEN WITH SAME SFList error or could set Iselected to bool? and null-->
<SfListView ID="DashboardTiles" TValue="@DataModel" DataSource="@Data" ShowCheckBox="true">
    <ListViewEvents TValue="@DataModel" Clicked="@((e) => OnTypeInfoSelected(e))" />
    <ListViewFieldSettings TValue="@DataModel" Id="@nameof(DataModel.Id)" Text="@nameof(DataModel.Text)" Enabled="@nameof(DataModel.IsEnabled)" IsChecked="brokenbinding"></ListViewFieldSettings>
</SfListView>

@code
{
    private List<DataModel> Data = new List<DataModel>
     {
                new DataModel { Text = "Abstract", Id = 4353 },
                new DataModel { Text = "Abstract", Id = 5 }
    };

    private class DataModel
    {
        public string Text { get; set; }
        public int Id { get; set; }
        public bool IsSelected { get; set; }
        public bool IsEnabled { get; set; }
    }
    
    private async Task OnTypeInfoSelected(ClickEventArgs<DataModel> e)
    {
        await Task.Run(() =>
        {
            if (e.ItemData != null)
            {
                // logic here
            }
        });
    }
}

Any assistance or direction here would be greatly appreciated
Regards
vincent


MK Muthukrishnan Kandasamy Syncfusion Team December 7, 2020 10:36 AM UTC

 
Hi Vincent, 
 
Thanks for sharing the details. 
 
We have validated your reported problem with your shared details. We were able to reproduce your reported problem with second code, because you have not defined brokenbinding attribute in DataModel class but you have assigned this attribute to IsChecked field. For resolving your problem, we need to add the defined attribute to ListView fields. Please refer to the below code block. 
 
 
<SfListView ID="DashboardTiles" TValue="@DataModel" DataSource="@Data" ShowCheckBox="true"> 
    <ListViewEvents TValue="@DataModel" Clicked="@((e) => OnTypeInfoSelected(e))" /> 
    <ListViewFieldSettings TValue="@DataModel" Id="@nameof(DataModel.Id)" Text="@nameof(DataModel.Text)" Enabled="@nameof(DataModel.IsEnabled)" IsChecked="brokenbinding"></ListViewFieldSettings> 
</SfListView> 
 
.. 
…. 
 
private class DataModel 
    { 
        public string Text { get; set; } 
        public int Id { get; set; } 
        public bool brokenbinding { get; set; } 
        public bool IsEnabled { get; set; } 
    } 
 
We have made some breaking changes in the ListView component from the release version 18.3.0.35. Please refer to the below link for more details. 
 
 
Also, we were unable to reproduce the same issue with first shared code block. We have prepared sample application for your convenience, which can be downloaded from the below link. 
 
 
If the issue still persists, as requested as earlier please share the issue replicating sample. It will be help us to provide you the prompt solution. 
 
Regards, 
Muthukrishnan K 


Marked as answer

VM Vincent McCarthy December 7, 2020 10:43 AM UTC

Hi Muthukrishnan

Thanks for the response. T
The broken binding in the last sample was only an illustration of what the error was - I knew the reason was because the model didnt have a value. 
It was to illustrate that sometimes in our application the sflist is rendering with a valid model property that checkbox should bind to but it still the same error null exception as in the example code.
I'm trying to figure out how this could possibly happen and that's what I'm looking for assistance with here.

Regards 
Vincent




MK Muthukrishnan Kandasamy Syncfusion Team December 8, 2020 11:05 AM UTC

 
Hi Vincent, 
 
Sorry for the inconvenience. 
 
We were unable to predict the exact cause of your reported problem with your provided details other than previously shared reason. As requested as earlier, please share the issue replication sample. It will be help us to provide you the prompt solution. 
 
Regards, 
Muthukrishnan K 


Loader.
Up arrow icon