NullReferenceException when changing binded SeriesCollection

Hi, I'm trying to get a chart updated 30x per second, but I'm getting NullReferenceException 

When the open the view, a circular buffer with 1000 points is being updated with 25 new samples every 25 miliseconds, working in a separeted thread. This means that every second the buffer is totally updated.

The chart is binded to a SeriesColection I try to update everytime the buffer is updated.
But, sometimes I get a NullReference Exception even though I check is the data is null before.

Besides the Exception, I'm not being able to get a constant flow of the chart. The fps vary a lot between 26 - 45. How can I manage to control it?
Am I updating SfChart in the right way?

Thanks.

The View (PlotPageView.xaml), its code begind (PlotPageView.xaml.cs), the ViewModel (PlotPageViewModel) and its BaseViewModel and the Model (PlotPageModel) is attached in the .rar file.

{System.NullReferenceException: Object reference not set to an instance of an object. at (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,object) at Com.Syncfusion.Charts.FastReflection.GetValue (System.Object item) [0x00000] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Com.Syncfusion.Charts.ChartSeries.GeneratePropertyPoints (System.String[] yPaths, System.Collections.Generic.IList`1[System.Double][] yLists) [0x0050d] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Com.Syncfusion.Charts.ChartSeries.GeneratePoints (System.String[] yPaths, System.Collections.Generic.IList`1[System.Double][] yValueLists) [0x0013c] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Com.Syncfusion.Charts.XyDataSeries.OnDataSourceChanged (System.Object oldValue, System.Object newValue) [0x00029] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Com.Syncfusion.Charts.ChartSeries.set_ItemsSource (System.Object value) [0x0003b] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Syncfusion.SfChart.XForms.Droid.ChartSeriesMapping.OnChartSeriesPropertiesChanged (System.String propertyName, Syncfusion.SfChart.XForms.ChartSeries formSeries, Com.Syncfusion.Charts.ChartSeries nativeSeries) [0x00243] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Syncfusion.SfChart.XForms.Droid.ChartSeriesMapping.OnCartesianSeriesPropertiesChanged (System.String propertyName, Syncfusion.SfChart.XForms.CartesianSeries formSeries, Com.Syncfusion.Charts.CartesianSeries nativeSeries) [0x0014f] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Syncfusion.SfChart.XForms.Droid.ChartSeriesMapping.OnXyDataSeriesPropertiesChanged (System.String propertyName, Syncfusion.SfChart.XForms.XyDataSeries formSeries, Com.Syncfusion.Charts.XyDataSeries nativeSeries) [0x00026] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Syncfusion.SfChart.XForms.Droid.ChartSeriesMapping.OnFastLineSeriesPropertiesChanged (System.String propertyName, Syncfusion.SfChart.XForms.FastLineSeries formSeries, Com.Syncfusion.Charts.FastLineSeries nativeSeries) [0x0004a] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Syncfusion.SfChart.XForms.Droid.ChartSeriesMapping.GetNativeSeries (Syncfusion.SfChart.XForms.ChartSeries chartSeries) [0x004c6] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at Syncfusion.SfChart.XForms.Droid.SfChartMapping.OnSeriesCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x001fb] in <82dcf2be2c634b0180ecb1b68f5c0f04>:0 at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs(object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object oldItem, System.Object newItem, System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:354 at System.Collections.ObjectModel.ObservableCollection`1[T].SetItem (System.Int32 index, T item) [0x0001c] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:210 at System.Collections.ObjectModel.Collection`1[T].set_Item (System.Int32 index, T value) [0x00027] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:59 at FirstBioRobApp.ViewModels.PlotPageViewModel+<>c__DisplayClass52_0.<Update_Graph_Series>b__0 () [0x00002] in D:\Programacao\repos\Mobile\FirstBioRobApp\FirstBioRobApp\FirstBioRobApp\ViewModels\PlotPageViewModel.cs:207 }



Attachment: FirstBioRobApp_b89ea6ff.rar

13 Replies 1 reply marked as answer

DD Devakumar Dhanapoosanam Syncfusion Team July 21, 2020 02:18 AM UTC

Hi Eduardo Arruda, 
 
Greetings from Syncfusion.  
Currently we are validating the reported query at our end and we will update you the complete details on or before July 22, 2020. 
 
Regards, 
Devakumar D 



DD Devakumar Dhanapoosanam Syncfusion Team July 23, 2020 07:45 PM UTC

Hi Eduardo Arruda, 
 
Sorry for the delay. 
 
Still we need some more time to analyze the reported issue and will update you the details on or before July 27, 2020.  
 
Regards, 
Devakumar D 



EA Eduardo Arruda July 24, 2020 12:11 AM UTC

Thank you for your reply,  Devakumar.
I'll wait, no problem.




YP Yuvaraj Palanisamy Syncfusion Team July 26, 2020 04:49 PM UTC

Hi Eduardo Arruda, 

Thank you for your reply. We will update you the status on  27th July 2020. 

Regards, 
Yuvaraj 



YP Yuvaraj Palanisamy Syncfusion Team July 27, 2020 10:19 AM UTC

Hi Eduardo Arruda, 

Thanks for your patience. 
  
We would like to let you know that with the provided sample file, we have created a sample and tested with multiple scenarios that are worked fine at our end. Please find the tested sample in below 
  
  
Hence, we have planned to fix the issue based on the provided stack trace and it will be expected to be included in our weekly NuGet on August 4, 2020. We will let you know once it has been rolled out.  
 
Meanwhile, could you please share the provided sample with a modified one to replicate this issue, that will help to find the exact root cause and ensure it with various related use cases.  Could you also please confirm whether the same issue occurred with Android or else other platforms too. 

Regards, 
Yuvaraj 



EA Eduardo Arruda replied to Yuvaraj Palanisamy July 27, 2020 04:24 PM UTC

Hi Eduardo Arruda, 

Thanks for your patience. 
  
We would like to let you know that with the provided sample file, we have created a sample and tested with multiple scenarios that are worked fine at our end. Please find the tested sample in below 
  
  
Hence, we have planned to fix the issue based on the provided stack trace and it will be expected to be included in our weekly NuGet on August 4, 2020. We will let you know once it has been rolled out.  
 
Meanwhile, could you please share the provided sample with a modified one to replicate this issue, that will help to find the exact root cause and ensure it with various related use cases.  Could you also please confirm whether the same issue occurred with Android or else other platforms too. 

Regards, 
Yuvaraj 


Hi Yuvaraj Palanisamy,
thanks for your reply.

I've made some minor changes on the code, mainly, the function "Update_Graph_Series()" was changed from a Task.Run to a new Thread (also, Task.Delay changed for Thread.Sleep).
With that change, the Android (on device and in sumulator) had improvements on performance. 
The number of times it got exceptions was reduced significantly, but still catch the same exception as before (an avarage of 1exception/minute). 

Unfortunantly, I cannot test it on IOs by now, only Android and UWP.
Android worked fine, but catch exceptions at a rate of 1x/min. 
UWP was not updating properly, the UI freezes the whole time, but I've seen no exception while it was running.

The sample project with modifications can be download from the link on my Google Drive, as its too big to share here.

Regards,
Eduardo Arruda



YP Yuvaraj Palanisamy Syncfusion Team July 28, 2020 02:15 PM UTC

Hi Eduardo Arruda,  
   
We need some more time to analyze the reported issue and will update you the details on or before July 30, 2020.   
  
Regards,  
Yuvaraj 



EA Eduardo Arruda July 29, 2020 02:24 PM UTC

I've tested on IOs.

It throws Exception much less often than on Android.
But the exception message was "System.Reflection.TargetException: Non-static method requires a target."

"System.Reflection.TargetException: Non-static method requires a target.\n  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00019] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:374 \n  at System.Reflection.RuntimePropertyInfo.GetValue (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) [0x00038] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimePropertyInfo.cs:442 \n  at System.Reflection.RuntimePropertyInfo.GetValue (System.Object obj, System.Object[] index) [0x00006] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimePropertyInfo.cs:429 \n  at System.Reflection.PropertyInfo.GetValue (System.Object obj) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Reflection/PropertyInfo.cs:43 \n  at Syncfusion.SfChart.iOS.FastReflection.GetValue (System.Object item) [0x00000] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.iOS.SFSeries.GeneratePropertyPoints (System.String[] yPaths, System.Collections.Generic.IList`1[System.Double][] yLists) [0x0050d] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.iOS.SFSeries.GeneratePoints (System.String[] yPaths, System.Collections.Generic.IList`1[System.Double][] yValueLists) [0x0013c] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.iOS.SFXyDataSeries.OnDataSourceChanged (System.Object oldValue, System.Object newValue) [0x00029] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.iOS.SFSeries.set_ItemsSource (System.Object value) [0x0003b] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.XForms.iOS.ChartSeriesMapping.OnChartSeriesPropertiesChanged (System.String propertyName, Syncfusion.SfChart.XForms.ChartSeries formSeries, Syncfusion.SfChart.iOS.SFSeries nativeSeries) [0x0027b] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.XForms.iOS.ChartSeriesMapping.OnCartesianSeriesPropertiesChanged (System.String propertyName, Syncfusion.SfChart.XForms.CartesianSeries formSeries, Syncfusion.SfChart.iOS.SFCartesianSeries nativeSeries) [0x00173] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.XForms.iOS.ChartSeriesMapping.OnXyDataSeriesPropertiesChanged (System.String propertyName, Syncfusion.SfChart.XForms.XyDataSeries formSeries, Syncfusion.SfChart.iOS.SFXyDataSeries nativeSeries) [0x00026] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.XForms.iOS.ChartSeriesMapping.OnFastLineSeriesPropertiesChanged (System.String propertyName, Syncfusion.SfChart.XForms.FastLineSeries formSeries, Syncfusion.SfChart.iOS.SFFastLineSeries nativeSeries) [0x0006f] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.XForms.iOS.ChartSeriesMapping.GetNativeSeries (Syncfusion.SfChart.XForms.ChartSeries chartSeries) [0x00532] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at Syncfusion.SfChart.XForms.iOS.SfChartMapping.OnSeriesCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x001b8] in <d785cff95f3f4fc5b7d87fdf8fe82d6d>:0 \n  at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs(object,System.Collections.Specialized.NotifyCollectionChangedEventArgs)\n  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 \n  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object oldItem, System.Object newItem, System.Int32 index) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:354 \n  at System.Collections.ObjectModel.ObservableCollection`1[T].SetItem (System.Int32 index, T item) [0x0001c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:210 \n  at System.Collections.ObjectModel.Collection`1[T].set_Item (System.Int32 index, T value) [0x00027] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:59 \n  at FirstBioRobApp.ViewModels.PlotPageViewModel+<>c__DisplayClass61_0.<Update_Graph_Series>b__0 () [0x00015] in /Users/dudu/Documents/BioRobApp01/FirstBioRobApp/FirstBioRobApp/ViewModels/PlotPageViewModel.cs:237 "


YP Yuvaraj Palanisamy Syncfusion Team July 30, 2020 02:31 PM UTC

Hi Eduardo Arruda,    
  
After discussed with developers, they have some concern on your sample provided. Please check and let us know your concern.   
  
As you are updating SeriesCollection and buffer collection in different thread. We face exception in android, while sometimes the PlotPageModel object from buffer collection became null internally, and series also try to handle the same object.  
  
And chart capable to notify for suspend the process until get notify from resume.   
  
Also, ChartSeries is capable of dynamic update of public properties, so no necessary to create same series in view model recursively.  Please check the below code changes and modified sample.   
  
 Xaml:  
<chart:SfChart x:Name="SfChart1"  
                VerticalOptions="FillAndExpand"  
               HorizontalOptions="FillAndExpand"  
               Series="{Binding SeriresCollection}"  
               >  
  
    . . .   
    <chart:SfChart.Series 
        <chart:FastLineSeries  XBindingPath = "XData" ItemsSource="{Binding TempBuffer}"  
        YBindingPath = "YData"  
        Color = "Red"  
        StrokeWidth = "1"/>  
    </chart:SfChart.Series 
  
</chart:SfChart 
  
C#  
public PlotPage()  
 
       InitializeComponent();  
       PlotPageViewModel viewModel = new PlotPageViewModel();  
       BindingContext = viewModel;// this;  
  
       viewModel.SuspendNotifiCation = new Action(SfChart1.SuspendSeriesNotification);  
       viewModel.ResumeNotification = new Action(SfChart1.ResumeSeriesNotification);  
 
  
ViewModel  
        . . .  
        public Action SuspendNotifiCation { get; set; }  
        public Action ResumeNotification { get; set; }  
  
        //Attributes  
        private ObservableCollection<PlotPageModel> tempBuffer;  
        public ObservableCollection<PlotPageModel> TempBuffer  
        {  
            get  
            {  
                return tempBuffer;  
            }  
            set  
            {  
                if (tempBuffer != value)  
                    tempBuffer = value;  
                OnPropertyChanged("TempBuffer");  
            }  
        }  
  
. . .  
. . .  
. . .  
private void UpdatePlotBuffer()  
 
    {  
        SuspendNotifiCation?.Invoke();  
        PlotPageModel[] PlotBuffer = new PlotPageModel[CircularBufferSize];  
        CircularBuffer.CopyTo(PlotBuffer, 0);  
  
        ObservableCollection<PlotPageModel> TempData = new ObservableCollection<PlotPageModel>();  
        foreach (PlotPageModel temp in PlotBuffer)  
         
            if (temp != null 
                TempData.Add(temp);  
        }  
  
        TempBuffer = TempData;  
        ResumeNotification?.Invoke();  
    }  
    }  
  
  
Let us know, if above change is differ from your use case.   
 
Regards, 
Yuvaraj 


Marked as answer

EA Eduardo Arruda July 31, 2020 08:07 PM UTC

Hi Yuvaraj,

Thank you for the detailed answer.
I'll try the modification and reach back to you.

Regards,
Eduardo Arruda


HM Hemalatha Marikumar Syncfusion Team August 3, 2020 07:02 AM UTC

Hi Eduardo Arruda, 
 
Thanks for your update.  
 
Please check this and let us know.  
 
Regards,
Hemalatha M. 
 
 
 



EA Eduardo Arruda August 3, 2020 09:46 PM UTC

Hi, 

So, the way I was updating the buffer was really causing null exceptions inside the application.
I've tested the provided sample on my app and it worked! Didn't faced any NullReferenceException.

I was updating the whole series because I was not being able to get "SuspendNotifiCation/ResumeNotification" to work on my viewModel.
The sample I provided before had only one series, but I intend to use 6 series. As I wasn't able to use "SuspendNotifiCation/ResumeNotification" I thought updating the whole SeriesCollection was a better option, otherwise I would update the chart once to each series (6times). 
Now that I've learned to Suspend and Resume, working with the series alone is a good and worth option.

Thank you very much.
It was really helpfull!

Now, I have another question about how to keep chart updating in a fixed frame per second rate. 
Should I start a new thread or I may question here?

Regards,
Eduardo Arruda






YP Yuvaraj Palanisamy Syncfusion Team August 4, 2020 12:39 PM UTC

Hi Eduardo Arruda, 

Thank you for your update. We are glad to hear that given solution works at your end.  
   
You can proceed here for your further assistance. Also please refer the below link for keep chart with updating the live data points.  
   

Regards, 
Yuvaraj 
  


Loader.
Up arrow icon