引发ErrorsChanged事件时,InotifyDataErrorInfo ArgumentOutOfRangeException

问题描述:

这是一个很奇怪的问题,在这一点上,我认为这可能与我的计算机配置有关.

This is a wierd one and at this point I am thinking that it may have something to do with my machines configuration.

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

Basically I have created a pretty standard implementation of INotifyDataErrorInfo and in certain circumstances, when raising the ErrorsChanged event I get an ArgumentOutOfRangeException. This exception doesn't contain much info; it gives me ArgumentOutOfRangeException crossed a native/managed boundary plus the standard ArgumentOutOfRangeException description regarding non-negative indexes and collection sizes. The InnerException is null. The stack trace is as follows:

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的另一种实现),并且其他任何注释中都没有提及我遇到的问题.谷歌搜索会出现一些无济于事的命中情况.

The reason I mention my machine configuration is because I have tried a couple of solutions posted to blogs (e.g. here and here) and get the same problem (i.e. not my code, another implementation of INotifyDataErrorInfo) and there is no mention in the comments of any others getting the problem I do. Googling turns up a couple of random hits that don't help.

所需状态如下:

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

更新:如果我将焦点从显示验证错误的TextBox移开,我也可以重现.

UPDATE: I can also reproduce if I move focus away from a TextBox displaying a validation error.

我有点想知道是否错过了Service Pack/更新之类的东西,因为从我看来,它看起来好像框架代码中有一个非常基本的错误,而同时它并没有发生其他人.

I'm kind of wondering if I've missed a service pack/update or something because from what I'm seeing it looks as though theres a pretty elementary error in the framework code and at the same time its not happening for others.

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

更新:与 更新:我现在已经在另一台计算机上测试了我的代码和提到的示例,并且工作正常.我仍然很想解决这个问题,因为它不能在我的常规机器上运行(到目前为止,我还没有遇到任何麻烦).任何有关我如何追踪造成这种情况的原因的建议,将不胜感激.我已经在问题机器上重新安装了Silverlight(运行时,SDK,工具包),但无法解决问题.

UPDATE: I have now tested my code and the mentioned samples on another machine and it works fine. I would still really like to resolve this as its a little unsettling that it isn't working on my regular machine (which I have not had any trouble with up until now). Any suggestions as to how I could track down what is causing this would be appreciated. I have re-installed Silverlight (Runtime, SDK, Toolkit) on the problem machine and this has not resolved the issue.

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

UPDATE: Here is the call stack of the framework code where the exception is occurring obtained by enabling source server support with MS symbol server:

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插件日志文件,而这些文件可能在这里没有帮助,有这样的日志吗?

UPDATE: The application runs fine (on the problem machine) without a debugger attached, works as expected and no unhandled exception scripts are invoked (This kinda had me stumped, could it be VS related?). I had a quick search on google to see if I could find any Silverlight plugin log file which may shed some light here with no luck, is there such a log?

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

I think it is binding error in TextBox template tooltip

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

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

Validation.Errors become empty but binding still has not updated its references.

我建议忽略该异常.取消选中调试设置"中的异常跨越AppDomain或被管理...时中断".

I recommend to ignore the exception. Uncheck "Break when exceptions cross AppDomain or managed...." in Debugging settings.