This project is read-only.

ArgumentNull error when binding SparrowChart to ObservableCollection in WPF

May 15, 2014 at 10:06 PM
In my MainWindow I have a DataGrid and some SparrowCharts bound to an ObservableCollection in my ViewModel.
The grid works fine but I get a null error when I bind the chart.

Here is my XAML:
<Window x:Class="DiskUseAnalysis.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DiskUseAnalysis"
        xmlns:sparrow="http://sparrowtoolkit.codeplex.com/wpf"  
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        Title="Disk Use Analysis" Height="950" Width="1200" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Visible">
    <Window.DataContext>
        <local:ViewModel />
    </Window.DataContext>
...
<DataGrid x:Name="ResultsGrid" Margin="10,10,10,10" SelectionMode="Extended"  Grid.Column="1" Grid.Row="2" ItemsSource="{Binding Path= FilteredResults}" FontSize="10" VerticalScrollBarVisibility="Visible" Height="700" AutoGeneratingColumn="DataGrid_AutoGeneratingColumn"/>

<sparrow:SparrowChart HorizontalAlignment="Left" Grid.Column="1" Grid.Row="3" Margin="10,0,0,0" Width="1000" Height="290">
                <sparrow:SparrowChart.Legend>
                    <sparrow:Legend Header="Disk Hold" Height="20" Margin="0,0,0,0" Width="107" FontSize="8" ShowIcon="False"/>
                </sparrow:SparrowChart.Legend>
                <sparrow:SparrowChart.XAxis>
                   <sparrow:DateTimeXAxis  StringFormat="HH:mm:ss.fff tt" />                   
                </sparrow:SparrowChart.XAxis>
                <sparrow:SparrowChart.YAxis>
                    <sparrow:LinearYAxis Header="Disk Hold Time" Margin="0"/>
                </sparrow:SparrowChart.YAxis>
                <sparrow:LineSeries PointsSource="{Binding FilteredResults}" XPath="X" YPath="DiskHold" Stroke="#FF2709E2" TextOptions.TextFormattingMode="Display" IsRefresh="True"/>
            </sparrow:SparrowChart>
Relevant portion of my class:
ObservableCollection<MyObject> filteredResults = new ObservableCollection<MyObject>();


public ObservableCollection<MyObject> FilteredResults
        {
            get
            {
                return filteredResults;
            }
            set
            {
                if (value!= null)  
                {
                    filteredResults = value;
                    OnPropertyChanged("FilteredResults");
                }
            }
        }
Here is where my OC is built:
var result = from anotherObject in AllEntries
                             where MeetsCriteria(anotherObject)
                             select anotherObject;  
                
FilteredResults = new ObservableCollection<MyObject>(result); 
When I try to run it, this happens:
System.ArgumentNullException was unhandled
  HResult=-2147467261
  Message=Value cannot be null.
Parameter name: method
  Source=System.Core
  ParamName=method
  StackTrace:
       at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
       at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression[] arguments)
       at Sparrow.Chart.FastProperty.InitializeSet()
       at Sparrow.Chart.FastProperty..ctor(PropertyInfo property)
       at Sparrow.Chart.SeriesBase.GetReflectionValues(String path, IEnumerable source, List`1 oldValues, Boolean isUpdate)
       at Sparrow.Chart.LineSeriesBase.GeneratePointsFromSource()
       at Sparrow.Chart.LineSeriesBase.PointsSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
       at Sparrow.Chart.LineSeriesBase.OnPointsSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
       at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
       at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
       at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
       at System.Windows.Data.BindingExpression.ScheduleTransfer(Boolean isASubPropertyChange)
       at MS.Internal.Data.ClrBindingWorker.NewValueAvailable(Boolean dependencySourcesChanged, Boolean initialValue, Boolean isASubPropertyChange)
       at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
       at MS.Internal.Data.ClrBindingWorker.OnSourcePropertyChanged(Object o, String propName)
       at MS.Internal.Data.PropertyPathWorker.OnPropertyChanged(Object sender, PropertyChangedEventArgs e)
       at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)
       at System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(Object sender, PropertyChangedEventArgs args)
       at DiskUseAnalysis.ViewModel.OnPropertyChanged(String propertyName) in c:\Users\robert\Documents\Visual Studio 2012\Projects\DiskUseAnalysis\DiskUseAnalysis\ViewModel.cs:line 620
       at DiskUseAnalysis.ViewModel.set_FilteredResults(ObservableCollection`1 value) in c:\Users\robert\Documents\Visual Studio 2012\Projects\DiskUseAnalysis\DiskUseAnalysis\ViewModel.cs:line 263
       at DiskUseAnalysis.ViewModel.BuildResultsUsingLINQ() in c:\Users\robert\Documents\Visual Studio 2012\Projects\DiskUseAnalysis\DiskUseAnalysis\ViewModel.cs:line 830
       at DiskUseAnalysis.ViewModel.BuildLikelySuspectsExecute() in c:\Users\robert\Documents\Visual Studio 2012\Projects\DiskUseAnalysis\DiskUseAnalysis\ViewModel.cs:line 755
       at MicroMvvm.RelayCommand.Execute(Object parameter) in c:\Users\robert\Documents\Visual Studio 2012\Projects\DiskUseAnalysis\MicroMvvm\RelayCommand.cs:line 147
       at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
(The form won't let me paste the whole thing).

Here is the method that raises the exception:
private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));                
            }
        }
If I examine the collection, it is not null and neither is anything in it.

If I comment out the chart the datagrid binds to the same Observable Collection with no problems.

Any suggestions?
May 16, 2014 at 2:54 PM
This morning I experienced a very similar issue. The same exception from the same method (System.Linq.Expressions.Expression.Call) was thrown. Message was also that the "method" can't be null. I discovered that this happened only when I used "System.Tuple" as collection elements (precisely: "Tuple<double, double>"). As soon as I switched back to the hand-coded class quoted below, the exception disappeared:
public class Model {
  public double X { get; set; }
  public double Y { get; set; }

  public Model(double x, double y) {
    X = x;
    Y = y;
  }
}
I can see you don't use "Tuple", nonetheless it might give you a clue as to real cause. If you discover it, share it with us, please!