【问题标题】:INotifyDataErrorInfo ArgumentOutOfRangeException when raising ErrorsChanged event引发 ErrorsChanged 事件时出现 INotifyDataErrorInfo ArgumentOutOfRangeException
【发布时间】:2010-10-03 22:55:38
【问题描述】:

这是一个奇怪的问题,此时我认为这可能与我的机器配置有关。

基本上我已经创建了一个非常标准的INotifyDataErrorInfo 实现,在某些情况下,当引发ErrorsChanged 事件时,我得到一个ArgumentOutOfRangeException。此异常不包含太多信息;它给了我ArgumentOutOfRangeException crossed a native/managed boundary 以及关于非负索引和集合大小的标准ArgumentOutOfRangeException 描述。 InnerException 为空。堆栈跟踪如下:

at System.ThrowHelper
        .ThrowArgumentOutOfRangeException(ExceptionArgument argument,
                                           ExceptionResource resource)
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at System.Collections.ObjectModel.Collection`1.get_Item(Int32 index)
at System.Collections.ObjectModel.ReadOnlyCollection`1.get_Item(Int32 index)

我提到我的机器配置的原因是因为我尝试了一些发布到博客上的解决方案(例如herehere)并且遇到了同样的问题(即不是我的代码,INotifyDataErrorInfo 的另一个实现)并且那里在任何其他人遇到我遇到的问题的 cmets 中都没有提及。谷歌搜索会发现一些无济于事的随机点击。

需要的状态如下:

  1. 我在控件中输入了一个值,从而触发了验证错误。 (这工作正常,错误文本按预期显示在 UI 中)。
  2. 然后我在控件中输入一个新值,以便验证成功并从错误集合中删除错误(HasErrors 返回 false)。
  3. ErrorsChanged 被引发以反映此更改成功验证且没有错误,并发生异常。

更新:如果我将焦点从显示验证错误的文本框上移开,我也可以重现。

我有点想知道我是否错过了服务包/更新或其他什么,因为从我所看到的情况来看,框架代码中似乎存在一个非常基本的错误,同时它并没有发生其他人。

更新:我使用的是 Silverlight 4 的最终 RTM 版本。不是 RC 或 Beta。

更新:我得到了与this whitepaper 提供的官方 MS 样本相同的结果。

更新:我现在已经在另一台机器上测试了我的代码和提到的示例,它工作正常。我仍然真的很想解决这个问题,因为它无法在我的常规机器上运行(到目前为止我还没有遇到任何问题),这有点令人不安。任何有关我如何追踪导致此问题的原因的建议将不胜感激。我已经在问题机器上重新安装了 Silverlight(运行时、SDK、工具包),但这并没有解决问题。

更新:以下是通过使用 MS 符号服务器启用源服务器支持获得的发生异常的框架代码的调用堆栈:

mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument argument, System.ExceptionResource resource) + 0x40 bytes 
  mscorlib.dll!System.ThrowHelper.ThrowArgumentOutOfRangeException() + 0x10 bytes 
  mscorlib.dll!System.Collections.Generic.List<System.Windows.Controls.ValidationError>.this[int].get(int index = 0) + 0x13 bytes 
  mscorlib.dll!System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationError>.this[int].get(int index) + 0x2e bytes 
  mscorlib.dll!System.Collections.ObjectModel.ReadOnlyCollection<System.Windows.Controls.ValidationError>.this[int].get(int index) + 0x2e bytes 
  [Native to Managed Transition] 
  [Managed to Native Transition] 
  System.Windows.dll!System.Windows.IndexerListener.Value.get() + 0xc3 bytes 
  System.Windows.dll!System.Windows.IndexerPathStep.Value.get() + 0x17 bytes 
  System.Windows.dll!System.Windows.PropertyPathListener.RaisePropertyPathStepChanged(System.Windows.PropertyPathStep source = {System.Windows.IndexerPathStep}) + 0x17 bytes 
  System.Windows.dll!System.Windows.IndexerPathStep.RaisePropertyPathStepChanged(System.Windows.PropertyListener source) + 0xe bytes 
  System.Windows.dll!System.Windows.IndexerListener.SourcePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs args) + 0xea bytes 
  System.Windows.dll!System.Windows.Data.WeakPropertyChangedListener.PropertyChangedCallback(object sender, System.ComponentModel.PropertyChangedEventArgs args) + 0x3d bytes 
  System.Windows.dll!System.Collections.ObjectModel.ReadOnlyObservableCollection<System.__Canon>.OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args) + 0x17 bytes 
  System.Windows.dll!System.Collections.ObjectModel.ReadOnlyObservableCollection<System.__Canon>.HandlePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + 0xe bytes 
  System.Windows.dll!System.Collections.ObjectModel.ObservableCollection<System.Windows.Controls.ValidationError>.OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e) + 0x37 bytes 
  System.Windows.dll!System.Collections.ObjectModel.ObservableCollection<System.Windows.Controls.ValidationError>.RemoveItem(int index = 0) + 0x79 bytes 
  mscorlib.dll!System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationError>.Remove(System.Windows.Controls.ValidationError item) + 0x75 bytes 
  System.Windows.dll!System.Windows.Controls.Validation.RemoveValidationError(System.Windows.FrameworkElement fe = {System.Windows.Controls.TextBox}, System.Windows.Controls.ValidationError error) + 0x40 bytes 
  System.Windows.dll!System.Windows.Data.BindingExpression.RemoveErrorFromTarget(System.Windows.Controls.ValidationError error) + 0x48 bytes 
  System.Windows.dll!System.Windows.Data.BindingExpression.NotifyOldDataErrorInfos(System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationError> validationErrors) + 0x73 bytes 
  System.Windows.dll!System.Windows.Data.BindingExpression.NotifyOldDataErrorInfos(bool isNotifyChildDataErrorInfo) + 0x25 bytes 
  System.Windows.dll!System.Windows.Data.BindingExpression.NotifyDataErrorInfo_ErrorsChanged(object sender, System.ComponentModel.DataErrorsChangedEventArgs e) + 0xad bytes 

更新: 应用程序在没有附加调试器的情况下运行良好(在问题机器上),按预期工作并且没有调用未处理的异常脚本(这有点让我难过,它可能与 VS 相关吗? )。我在 google 上进行了快速搜索,看看是否可以找到任何 Silverlight 插件日志文件,这可能会在没有运气的情况下在这里有所帮助,是否有这样的日志?

【问题讨论】:

  • 我在 VS2012 上与 SL5 有同样的错误
  • 你找到答案了吗?我在没有 silverlight stackoverflow.com/questions/15824070/… 的情况下也有类似的问题
  • @kirsten 不抱歉,没有找到解决方案。只能在那个带有调试器的盒子上重现,所以永远找不到它是什么。
  • 我有同样的问题 - 没有 SilverLight,只是普通的 WPF。它实际上并没有抛出异常,或者至少没有一个 a 可以捕获,但它确实引发了如下绑定错误:(0)[0].ErrorContext。未能获得价值。 ArgumentOutOfRangeException:'SystemArgumentOutOfRangeException: 指定的参数超出了有效值的范围。这真的很烦人,因为我希望我的代码没有绑定错误。

标签: silverlight validation silverlight-4.0 inotifydataerrorinfo


【解决方案1】:

我认为这是 TextBox 模板工​​具提示中的绑定错误

{Binding (Validation.Errors)[0].ErrorContent}

Validation.Errors 变为空,但绑定仍未更新其引用。

我建议忽略该异常。在调试设置中取消选中“异常跨 AppDomain 或托管时中断....”。

【讨论】:

  • 我在我的电脑上试了一下,效果很好。我有点怀疑这是否会导致其他类型的异常出现其他问题,但我检查了我同事的其他 3 个 VS 2010 安装,默认情况下他们都未选中此选项。所以我想这确实是解决这个问题的正确方法。
【解决方案2】:

我能够通过从 Web 项目中删除 Silverlight 应用程序链接并重新添加它们来解决此问题。

希望这会有所帮助。

【讨论】:

  • 很抱歉听到这个消息。奇怪的是,我没有检查更改,而是通过撤消 Web 项目上的待处理更改并使用原始文件重新构建来进行实验,令我惊讶的是,问题并没有再次出现。我还取消选中(然后重新选中)Web 项目中的 Debug 选项,并且与解析过程中项目的 RIA 链接相同。每次我对整个解决方案进行重建。这很奇怪,因为我只在新安装的机器上发现这个错误。
【解决方案3】:

在这种情况下,本机代码可能会引发两种不同的异常。无论您在 catch 中放入(或不放入)什么,都不会被 try...catch 块捕获。

一个是“ArgumentOutOfRangeException 越过了本机/托管边界”。要停止看到这个,您需要在工具 > 选项 > 调试 > 常规中取消选中“异常跨越 AppDomain 或托管/本机边界时中断(仅限托管)”。

另一个只是“ArgumentOutOfRangeException”。要停止看到这个,您需要在“工具”>“选项”>“调试”>“常规”中选中“仅启用我的代码”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多