Editing a DataGrid in WPF causes a System.NullReferenceException
See the question and my original answer on StackOverflowPoking with .NET Reflector, this is the code you're running into (in System.Windows.Data.BindingExpression):
internal override object ConvertProposedValue(object value)
{
...
Type sourcePropertyType = this.Worker.SourcePropertyType;
IValueConverter dynamicConverter = null;
CultureInfo culture = base.GetCulture();
if (this.Converter != null)
{
if (!base.UseDefaultValueConverter)
{
value = this.Converter.ConvertBack(value, sourcePropertyType, this.ParentBinding.ConverterParameter, culture);
if (((value != Binding.DoNothing) && (value != DependencyProperty.UnsetValue)) && !this.IsValidValueForUpdate(value, sourcePropertyType))
{
dynamicConverter = this.DynamicConverter;
}
}
From what I can understand the "SourcePropertyType" is a null value (and then it throws in the call to IsValidValueForUpdate
).
So, this is clearly a bug in PresentationFramework (it sould report a nice error and fail gracefully), but it happens because somehow, you pass to WPF a source property type that is null. Maybe because of a generic open type or an anonymouse type.
Hope this helps.
To help you diagnose, I suggest you turn WPF traces one, see this thread on this subject on SO: How to detect broken WPF Data binding?