0

I am having a weird problem with my C# code and binding. The code works fine when I run it as the .exe or when I run it on another machine running windows 7 64 bit in debug mode. This problem only occurs when I am debugging on a particular machine. An exception of type 'System.ArgumentNullException' occurred in System.dll but was not handled in user code. I cannot figure out what the problem is. I have commented some code that I added which gets rid of the problem but I cannot figure out why it only happens on one machine.

I found an interesting post regarding a bug in .net 4.5 Combobox SelectedItem DataBinding NullReference Exception

Here is the code that causes the exception and is bound to a data

private ObservableCollection<DataPoint> _pin1 { get; set; }

    public IList<DataPoint> Pin_1 { get; set; }

    public ObservableCollection<DataPoint> Pin1
    {
        get
        {
            //if(Pin_1 != null)
            return _pin1 = new ObservableCollection<DataPoint>(Pin_1);
            //return _pin1 = null;
        }
        set
        {
            if (_pin1 != value)
            {
                _pin1 = value;
                OnPropertyChanged("Pin1");
            }
        }
    }

I have looked at the following similar problems and feel that these might be what I am experiencing.

Two-way binding with Windows Forms ComboBox throws NullReferenceException when changed

What is a NullReferenceException, and how do I fix it?

Community
  • 1
  • 1
Brett
  • 1
  • 1
  • My guess is somehow `Pin_1` is null, which is passed to `ObservableCollection` constructor throws exception. Investigate why `Pin_1` is null. May be because of some other exception? – Sriram Sakthivel Aug 01 '14 at 17:53
  • Pin_1 should be null as I haven't added any data to it. My biggest confusion is why does this exception only happen on one computer and only during debug. Can you not have null ObservableCollections? – Brett Aug 01 '14 at 18:35

0 Answers0