GWLlosa
GWLlosa

Reputation: 24403

How to Debug WPF Exceptions that don't have Your Code in the Stack Trace?

We have code that is producing the following unhandled exception:

Error Message: System.Reflection.TargetParameterCountException: Parameter count mismatch.

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

at System.Delegate.DynamicInvokeImpl(Object[] args)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler). Stack Trace: System.Reflection.TargetParameterCountException: Parameter count mismatch.

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

at System.Delegate.DynamicInvokeImpl(Object[] args)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler).

We know when this happens. We are adding an item to an ObservableCollection that is bound to by the UI. However, we're at a loss to explain WHY this happens, or HOW to fix it, given that the error only happens rarely. Since its a sporadic issue, its not likely to be some kind of typo in the Bindings or the DataTemplates, as those would be expected to go wrong 'every' time. Nowhere in our code do we use Reflection or anything that would be expected to invoke parameters at run-time; the exception must be referring to some internal classes from Microsoft. Further, the stack trace only contains Microsoft code; we've been unable to find any documentation for many of the classes in the stack trace itself (i.e., System.Windows.Threading.ExceptionWrapper). How can we debug this kind of error? Is there a way to put breakpoints of some sort inside these internal Microsoft classes so that we can see what sorts of inputs are triggering this behaviour?

Upvotes: 3

Views: 1347

Answers (1)

John Sobolewski
John Sobolewski

Reputation: 4572

You may be able to determine what was going on when the app died by capturing a crash dump.

Check this question out for more info

How do I obtain a crash dump

Upvotes: 1

Related Questions