2011-06-14 96 views
4

我正在開發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

我不確定究竟發生了什麼,但事實證明,我可以跳過錯誤調試時,一切正常。而且,在沒有調試的情況下運行時甚至不會出現這些錯誤,所以我現在只會忽略它。

+1

你有沒有什麼好運氣?我有一個類似的驗證問題,沒有調試就可以正常工作,但是在調試時非常煩人。 – Entrodus 2011-11-25 09:59:17

1

在我的情況下,答案是在調試設置中取消選中「在異常跨AppDomain或管理....時中斷」。

source

+0

試過了,沒有幫助 – Shimmy 2012-01-29 05:24:41