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.OnEmailChang开发者_Go百科ed();
}
}
}
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.
I'm not sure what exactly was happening still, but it turns out I can just skip past the errors when debugging and everything works fine. Also, the errors don't even occur when running without debugging, so I'm just going to ignore it for now.
The answer in my case was to Uncheck "Break when exceptions cross AppDomain or managed...." in Debugging settings.
source
精彩评论