Silverlight验证在修复验证错误后抛出异常

问题描述:

我正在开发Silverlight业务应用程序,并且正在进行第一次验证。当我收到验证错误时,控件会按预期显示错误,但是当我修复验证错误并移动到DataForm中的下一个字段时(实际上是Telerik RadDataForm,它的价值),我得到一个ArgumentOutOfRangeException抛出在.g.cs文件中的实体的setter中。下面是生成的代码:Silverlight验证在修复验证错误后抛出异常

[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(); 
     } 
    } 
} 

而这里的XAML中的控制是造成验证:

<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> 

而这里的异常的文本:

{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)} 

有谁知道为什么会这样正在抛出异常,还是有一个很好的调试策略?我无法介入实际抛出异常的代码。

我不确定究竟发生了什么,但事实证明,我可以跳过错误调试时,一切正常。而且,在没有调试的情况下运行时甚至不会出现这些错误,所以我现在只会忽略它。

+1

你有没有什么好运气?我有一个类似的验证问题,没有调试就可以正常工作,但是在调试时非常烦人。 – Entrodus 2011-11-25 09:59:17

在我的情况下,答案是在调试设置中取消选中“在异常跨AppDomain或管理....时中断”。

source

+0

试过了,没有帮助 – Shimmy 2012-01-29 05:24:41