DataObjectBase IDataErrorInfo error

Topics: Feature requests
Jun 22, 2012 at 9:31 AM
Edited Jun 22, 2012 at 10:18 AM

Hi Geert,

after updating to the latest telerik libraries i cannot get my application run anymore. i always get the following exception:

Type : System.ArgumentException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Argument 'propertyName' cannot be null or whitespace
Parameter name: propertyName
Source : Catel.Core
Help link :
ParamName : propertyName
Data : System.Collections.ListDictionaryInternal
TargetSite : Void IsNotNullOrWhitespace(System.String, System.String)
Stack Trace :    at Catel.Argument.IsNotNullOrWhitespace(String paramName, String paramValue) in c:\Source\Catel\src\Catel.Core.NET35\Argument.cs:line 89
   at Catel.Data.ValidationContext.GetFieldErrors(String propertyName) in c:\Source\Catel\src\Catel.Core.NET35\Data\ValidationContext.cs:line 536
   at Catel.Data.DataObjectBase.System.ComponentModel.IDataErrorInfo.get_Item(String columnName) in c:\Source\Catel\src\Catel.Core.NET35\Data\DataObjectBase.validation.cs:line 879
   at Telerik.Windows.Data.DataErrorInfoExtensions.GetErrorsForProperty(IDataErrorInfo dataErrorInfo, String propertyName)
   at Telerik.Windows.Controls.GridViewBoundColumnBase.GetDataErrorValidationErrors(Object dataItem, String propertyName)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.GetAllDataErrorsForItem(Object dataItem)
   at Telerik.Windows.Controls.GridView.GridViewRow.PrepareRow(Object item, GridViewDataControl owningDataGrid)

i looked at the sources and discovered the following. An empty property string is passed down to catel which causes the ArgumentException.... 

GridViewBoundColumnBase.GetDataErrorValidationErrors(dataItem, string.Empty)

Would it be possible to relax the IDataErrorInfo and IDataWarningInfo[string propertyName] so that an empty property string does not cause an exception?

// Catel.Data.DataObjectBase
string IDataErrorInfo.this[string columnName]
{
	get
	{
      // ------------ FIX
                  if (string.IsNullOrEmpty(columnName))
                  {
                            return string.Empty;
                  }
		if (this.HideValidationResults)
		{
			return string.Empty;
		}
		if (!this.IsValidated && this.AutomaticallyValidateOnPropertyChanged)
		{
			this.Validate(false);
		}
		string error = (
			from fieldError in this.ValidationContext.GetFieldErrors(columnName)
			select fieldError.Message).FirstOrDefault<string>();
		return error ?? string.Empty;
	}
}

// Catel.Data.DataObjectBase
string IDataWarningInfo.this[string columnName]
{
	get
	{
      // ------------ FIX
                  if (string.IsNullOrEmpty(columnName))
                  {
                            return string.Empty;
                  }
		if (this.HideValidationResults)
		{
			return string.Empty;
		}
		if (!this.IsValidated && this.AutomaticallyValidateOnPropertyChanged)
		{
			this.Validate(false);
		}
		string warning = (
			from fieldWarning in this.ValidationContext.GetFieldWarnings(columnName)
			select fieldWarning.Message).FirstOrDefault<string>();
		return warning ?? string.Empty;
	}
}

Thanks a lot!

Coordinator
Jun 22, 2012 at 4:37 PM

I will have to write unit tests first for this. I will see if I can bring it into the RC1.

Coordinator
Jun 22, 2012 at 4:44 PM

Implemented, I will release a new version tomorrow. For today, I am done working.

Jun 22, 2012 at 10:58 PM

Many thanks for the fast fix!