这个问题比较奇怪,我认为它可能与我的机器配置有关。
基本上,我创建了一个相当标准的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)
我提到我的机器配置是因为我尝试了一些发布在博客上的解决方案(例如这里和这里),并且遇到了相同的问题(即不是我的代码,而是INotifyDataErrorInfo的另一个实现),而在评论中没有任何其他人发现我遇到的问题。谷歌搜索出现了几个无关的结果。需要的状态如下:
- 我输入到控件中的值会触发验证错误(这很好,错误文本按预期在界面上显示)。
- 然后我输入一个新值到控件中,验证将成功,并从错误集合中删除错误(HasErrors返回false)。
- ErrorsChanged被引发以反映不带错误的成功验证的更改,并出现异常。
更新:如果我将焦点移开显示验证错误的TextBox,也可以复现此问题。
我有点想知道是否错过了服务包/更新之类的东西,因为从我的看法来看,在框架代码中有一个非常基本的错误,同时,它对于其他人来说并没有发生。
更新:我使用的是Silverlight 4的最终RTM版。不是RC或Beta。
更新:我在这篇白皮书中提供的官方MS示例中也得到了相同的结果。
更新:我现在已经在另一台机器上测试了我的代码和提到的样本,一切正常。尽管如此,我仍然希望解决这个问题,因为它没有在我的常规机器上工作(直到现在我还没有遇到任何问题)。如果您有任何建议可以追踪导致此问题的原因,将不胜感激。我在问题机器上重新安装了Silverlight(Runtime、SDK、Toolkit),但问题仍然存在。
更新:以下是启用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有关?)。 我快速搜索了一下谷歌,看看是否可以找到任何可记录此处信息的Silverlight插件日志文件,但没有成功,是否存在这样的日志文件?