Tuesday, August 3, 2010

Silverlight 4 "Value does not fall within the expected range"


I ported some WPF code to Silverlight 4 and started to receive a System.ArgumentException with the following message:
Value does not fall within the expected range.
Various posts indicated that this typically occurs when you dynamically add child objects with the same names to a container. However, I wasn't dynamically adding anything. After selectively commenting out portions of my XAML I was able to determine that the culprit was a DataGridTextColumn that had no binding attribute declared at all. Example:

<sdk:DataGridTextColumn Header="Pending Time" IsReadOnly="True" />
What surprised me was that when I specified a fictional binding ({Binding Foo}) I got a nice, easy to understand exception:
System.Windows.Data Error: BindingExpression path error: 'Foo' property not found on...
Granted, I am not a Silverlight expert so I might be posting something obvious. I hope that this saves someone some time.

2 comments: