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. Image for the cookie policy date
close icon

NullReferenceException when trying to update List Based on another selection

I have a common issue which I will explain one specific event 

The comon exception is :

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

at Syncfusion.Android.ComboBox.SfComboBox.Handle_CollectionChanged 

(System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)

[0x00000] in <6d1ab70763e74d7cbbdad401f96975a6>: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 

<2b1467cde5f6428d89ddadc0df922c3d>:0   at System.

Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged 

(System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) 

[0x00009] in <2b1467cde5f6428d89ddadc0df922c3d>:0  

at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (System.Int32 index, T item) [0x0001a] in <2b1467cde5f6428d89ddadc0df922c3d>:0  

at System.Collections.ObjectModel.Collection`1[T].Add (T item) [0x00020] in <46c2fa109b574c7ea6739f9fe2350976>:0  

.. then ref my code lines"

this happens after the VM and page is visable if I update the data inside the Bound Observable collection


In this situation I have two SfComboBoxes , I load the first combo box with a list of availible programs from the database

when the user selects a program I load in the next comboBox a list of Term Lengths, "1 Year","2 Years", etc.... 

private ObservableCollection<string> _programCodes;

public ObservableCollection<string> ProgramCodes{ get { return _programCodes; }set{SetProperty(ref _programCodes, value);}}

private ValidatableObject<string> _programCode;

public ValidatableObject<string> SelectedProgramCode{get { return _selectedProgramCode; }set{if (_selectedProgramCode != value){SetProperty(ref _selectedProgramCode, value);}}}

private ObservableCollection<ProgramTerms> _Terms;

public ObservableCollection<ProgramTerms> Terms {get {  return _terms;} set {  SetProperty(ref _terms, value);  }   }


I have Added a Behavior in the Xaml 

<behaviors:EventToCommandBehavior EventName="SelectionChanged" Command="{Binding GasProgramCodeSelectedCommand}" />

which is bound to this command in the ViewModel

public ICommand ProgramCodeSelectedCommand => new Command(() => {

            ShowVersionCode = !string.IsNullOrWhiteSpace(_selectedProgramCode.Value);

            SetTermsAvailible(GasTerms, _selectedProgramCode.Value, 1, _selectedCustomerType.Value.ID);          

        });


private void SetTermsAvailible(ObservableCollection<ProgramTerms> refTerms, string programCode, int serviceTypeId, int customerTypeId)

{

...

...

.. Stuff that doesn't break

//When I get here this is where the exception blows up.

foreach (var term in newTermsList)

{

refTerms.Add(term);

}

}


2 Replies

KG Kanimozhi Gunasekaran Syncfusion Team October 13, 2019 07:13 AM UTC

Hi Marios Kimonos,

Greetings from Syncfusion.

We are checking reported issue with high priority and will update you the status on October 15,2019. We appreciate your patience until then.

Regards,
Kanimozhi G.


HM Hemalatha Marikumar Syncfusion Team October 15, 2019 12:05 PM UTC

Hi Marios Kimonos,

Thanks for your patience. 
 
We have checked the reported crash issue in SfComboBox with below attached sample in Android platform. The sample has been prepared based on the provided code example and we tried to reassemble your requirement. We were unable to reproduce the reported issue with that. 
 
 
Please check with the sample and if the reported issue still occurs, update us with the following 
 
  • Modified sample of attached sample with issue reproducing steps
  • Update us with Xamarin.Forms version and used device configuration
 
Which will be helpful for us to analyze further and provide an appropriate solution. 
 
Regards,
Hemalatha M. 


Loader.
Live Chat Icon For mobile
Up arrow icon