I'm working on a Silverlight business app at the moment, and am getting into validation for the first time. When I get a validation error, the control will show the error as expected, but when I fix the validation error and move to the next field in the DataForm (actually a Telerik RadDataForm, for what it's worth), I'm getting an ArgumentOutOfRangeException thrown in my entity's setter in the .g.cs file. Here's the generated code:
[DataMember()]
[Display(Name="Email / User Name")]
[RegularExpression("^.*@.*\\..*$", ErrorMessage="Must be a valid e-mail address")]
[Required()]
public string Email
{
get
{
return this._email;
}
set
{
if ((this._email != value))
{
this.OnEmailChanging(value);
this.RaiseDataMemberChanging("Email");
this.ValidateProperty("Email", value); // <-- Exception thrown here
this._email = value;
this.RaiseDataMemberChanged("Email");
this.OnEmailChanged();
}
}
}
And here's the Xaml for the control that's causing validation:
<telerik:RadDataForm Grid.Row="0" Style="{StaticResource GridPageFormStyle}"
x:Name="addForm" EditEnded="AddEnded" Header="Add">
<telerik:RadDataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<telerik:DataFormDataField
DataMemberBinding="{Binding Email, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
Label="E-mail Address" />
<telerik:DataFormComboBoxField
DataMemberBinding="{Binding Role, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
ItemsSource="{Binding Roles, ElementName=This}" Label="Role" />
<telerik:DataFormComboBoxField DataMemberBinding="{Binding Partner, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
ItemsSource="{Binding Partners, ElementName=This}" Label="Partner" />
</StackPanel>
</DataTemplate>
</telerik:RadDataForm.EditTemplate>
</telerik:RadDataForm>
And here's the text of the exception:
{System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)}
Does anyone know why this exception is being thrown, or have a good strategy for debugging it? I can't step into the code that's actually throwing the exception.