-1

In my c# MVVM program. I set one observable collections. And I add to the image from the list. But i get Object reference not set to an instance of an object error.

   private ObservableCollection<SpecialAttractionImageModel> _SpecialAttractionImageModelObj = new ObservableCollection<SpecialAttractionImageModel>();

    public ObservableCollection<SpecialAttractionImageModel> SpecialAttractionImageModelObj
            {
                get { return _SpecialAttractionImageModelObj; }
                set
                {
                    _SpecialAttractionImageModelObj = value;
                    OnPropertyChanged("SpecialAttractionImageModelObj");
                }
            }

foreach (String file in fd.FileNames)
                    {
                        FileInfo currentFile = new FileInfo(file);
                        _SpecialAttractionImageModelObj.Add(new SpecialAttractionImageModel()
                        {
                            AttractionImageGid = "new",
                            SpecialAttracionImagePath = file,
                            IsChecked=false
                        });
                    }
manoj mano
  • 19
  • 2

1 Answers1

-1

Object is not initialized, maybe OnPropertyChanged("SpecialAttractionImageModelObj"); is the cause.

Stack Trace would help you figure out where this is happening.