这是一个奇怪的问题,此时我认为它可能与我的机器配置有关。
基本上我已经创建了一个相当标准的实现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 and here)并遇到同样的问题(即不是我的代码,INotifyDataErrorInfo 的另一个实现),并且在任何其他人遇到我遇到的问题的评论中都没有提及。谷歌搜索发现了一些没有帮助的随机点击。
所需状态如下:
- 我已在控件中输入一个值,从而触发验证错误。 (这工作正常,错误文本按预期显示在 UI 中)。
- 然后,我在控件中输入一个新值,以便验证成功并从错误集合中删除错误(HasErrors 返回 false)。
- 引发 ErrorsChanged 以反映此更改以成功验证且没有错误,并且发生异常。
UPDATE:如果我将焦点从显示验证错误的文本框移开,我也可以重现。
我有点想知道我是否错过了服务包/更新或其他东西,因为从我所看到的来看,框架代码中似乎存在一个非常基本的错误,同时它不会发生在其他人身上。
更新:我正在使用 Silverlight 4 的最终 RTM 版本。不是 RC 或 Beta。
UPDATE:我与提供的官方 MS 示例得到了相同的结果本白皮书.
UPDATE:我现在已经在另一台机器上测试了我的代码和提到的示例,它工作正常。我仍然很想解决这个问题,因为它不能在我的常规机器上运行(到目前为止我还没有遇到任何问题),这有点令人不安。任何有关我如何找出导致此问题的原因的建议将不胜感激。我已经在有问题的机器上重新安装了 Silverlight(运行时、SDK、工具包),但这并没有解决问题。
UPDATE:以下是通过启用 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
UPDATE:应用程序在没有附加调试器的情况下运行良好(在有问题的机器上),按预期工作,并且没有调用未处理的异常脚本(这有点让我难住了,它可能与 VS 相关吗?)。我在谷歌上进行了快速搜索,看看是否可以找到任何 Silverlight 插件日志文件,该文件可能会在这里提供一些启示,但运气不佳,有这样的日志吗?