【问题标题】:Silveright validation throws exception after fixing a validation errorSilveright 验证在修复验证错误后引发异常
【发布时间】:2011-11-25 18:20:42
【问题描述】:

我目前正在开发 Silverlight 商业应用程序,并且是第一次进行验证。当我收到验证错误时,控件将按预期显示错误,但是当我修复验证错误并移至 DataForm 中的下一个字段(实际上是 Telerik RadDataForm,值得一提)时,我得到了 ArgumentOutOfRangeException在 .g.cs 文件中我的实体设置器中抛出。这是生成的代码:

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

有谁知道为什么会抛出这个异常,或者有一个很好的调试策略吗?我无法进入实际引发异常的代码。

【问题讨论】:

    标签: c# .net silverlight


    【解决方案1】:

    我不确定到底发生了什么,但事实证明我可以在调试时跳过错误并且一切正常。另外,在不调试的情况下运行时甚至不会出现错误,所以我现在将忽略它。

    【讨论】:

    • 你有运气吗?我有一个类似的验证问题,无需调试即可正常工作,但调试时非常烦人。
    【解决方案2】:

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

    source

    【讨论】:

      猜你喜欢
      • 2013-11-18
      • 2014-10-17
      • 1970-01-01
      • 2020-08-04
      • 2013-03-27
      • 2012-03-11
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多