INotifyDataErrorInfo ArgumentOutOfRangeException when raising ErrorsChanged event
Asked Answered
A

3

11

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

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)

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.

The state required is as follows:

  1. I have entered a value in to the control such that a validation error is triggered. (This works fine, the error text is displayed in the UI as expected).
  2. I then enter a new value in to the control such that validation will succeed and errors are removed from the error collection (HasErrors returns false).
  3. ErrorsChanged is being raised to reflect this change to successful validation with no errors, and the exception occurs.

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

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.

UPDATE: I am using the final RTM build of Silverlight 4. NOT an RC or Beta.

UPDATE: I get the same result with the official MS sample provided with this whitepaper.

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.

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 

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?

Architrave answered 3/10, 2010 at 22:55 Comment(4)
I have same error with SL5 on VS2012Juback
Did you ever find an answer? I am having similar issues without silverlight #15824570Envisage
@kirsten No sorry, didn't find a solution. Could only ever repro on that box with a debugger attached so never found what it was.Architrave
I have the same problem - no SilverLight, just ordinary WPF. It doesn't actually throw an exception, or at least not one a can catch, but it does raise a binding error like this: (0)[0].ErrorContext. failed to get value. ArgumentOutOfRangeException:'SystemArgumentOutOfRangeException: Specified argument was out of range of valid values. This is really annoying as I prefer my code not to have binding errors.Cari
V
3

I think it is binding error in TextBox template tooltip

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

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

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

Violation answered 3/10, 2010 at 22:55 Comment(1)
I tried it on my computer and it works like a charm. I was a little sceptical on on whether this could cause other issues on other kind of exceptions but i checked 3 other installations of VS 2010 on my co-workers and they all had this option unchecked by default. So i guess this indeed is the right way to solve this problem.Blondy
L
0

There are two different possible exceptions that get thrown from native code in this situation. Neither is caught by a try...catch block, no matter what you put (or don't put) in the catch.

One is "ArgumentOutOfRangeException crossed a native/managed boundary". To stop seeing this one, you need to uncheck "Break when exceptions cross AppDomain or managed/native boundaries (Managed only)" in Tools > Options > Debugging > General.

The other one is just "ArgumentOutOfRangeException". To stop seeing this one, you need to check "Enable Just My Code" in Tools > Options > Debugging > General.

Livvy answered 3/10, 2010 at 22:55 Comment(0)
W
0

I was able to fix this problem by removing the Silverlight application links from the web project and re-adding them.

Hope this helps.

Worriment answered 3/10, 2010 at 22:55 Comment(1)
Sorry to hear that. The strange thing is that I didn’t check in the changes, instead experimented by undoing the pending changes on the web project and rebuilding with the original files, to my surprise the problem did not reappear. I also unchecked (then rechecked) the Debug option in the web project and same with the RIA links to the projects in the process of resolving. Each time I did a Rebuild of the entire solution. Its bizarre as I’m only finding this error on machines with new installs.Worriment

© 2022 - 2024 — McMap. All rights reserved.