【发布时间】: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)
我提到我的机器配置的原因是因为我尝试了一些发布到博客上的解决方案(例如here 和here)并且遇到了同样的问题(即不是我的代码,INotifyDataErrorInfo 的另一个实现)并且那里在任何其他人遇到我遇到的问题的 cmets 中都没有提及。谷歌搜索会发现一些无济于事的随机点击。
需要的状态如下:
- 我在控件中输入了一个值,从而触发了验证错误。 (这工作正常,错误文本按预期显示在 UI 中)。
- 然后我在控件中输入一个新值,以便验证成功并从错误集合中删除错误(HasErrors 返回 false)。
- 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