I hope someone on StackOverflow would help me out with the following problem:
I have a WP7.1 project, that I open using VS2012. Also, I have enable Common Language Runtime Exceptions. By doing this I wanted to catch and fix most bugs that I may have in the code.
When running the project in the emulator I get the following exceptions:
System.Reflection.TargetInvocationException occurred
Message=TargetInvocationException
StackTrace:
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[] index, StackCrawlMark& stackMark)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at System.Windows.CLRPropertyListener.get_Value()
at System.Windows.PropertyAccessPathStep.ConnectToPropertyInSource(Boolean isSourceCollectionViewCurrentItem)
at System.Windows.PropertyAccessPathStep.ConnectToProperty()
at System.Windows.PropertyAccessPathStep.ReConnect(Object newSource)
at System.Windows.PropertyPathListener.ReConnect(Object source)
at System.Windows.Data.BindingExpression.SourceAcquired()
at System.Windows.Data.BindingExpression.TargetLoaded(Object o, RoutedEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
InnerException: System.InvalidOperationException
Message=InvalidOperationException
StackTrace:
at System.Windows.Duration.get_TimeSpan()
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[] index, StackCrawlMark& stackMark)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at System.Windows.CLRPropertyListener.get_Value()
at System.Windows.PropertyAccessPathStep.ConnectToPropertyInSource(Boolean isSourceCollectionViewCurrentItem)
at System.Windows.PropertyAccessPathStep.ConnectToProperty()
at System.Windows.PropertyAccessPathStep.ReConnect(Object newSource)
at System.Windows.PropertyPathListener.ReConnect(Object source)
at System.Windows.Data.BindingExpression.SourceAcquired()
at System.Windows.Data.BindingExpression.TargetLoaded(Object o, RoutedEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
And
System.InvalidOperationException occurred
Message=InvalidOperationException
StackTrace:
at System.Windows.Duration.get_TimeSpan()
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.RuntimePropertyInfo.InternalGetValue(PropertyInfo thisProperty, Object obj, Object[] index, StackCrawlMark& stackMark)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at System.Windows.CLRPropertyListener.get_Value()
at System.Windows.PropertyAccessPathStep.ConnectToPropertyInSource(Boolean isSourceCollectionViewCurrentItem)
at System.Windows.PropertyAccessPathStep.ConnectToProperty()
at System.Windows.PropertyAccessPathStep.ReConnect(Object newSource)
at System.Windows.PropertyPathListener.ReConnect(Object source)
at System.Windows.Data.BindingExpression.SourceAcquired()
at System.Windows.Data.BindingExpression.TargetLoaded(Object o, RoutedEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex,
String eventName)
Apparently both exceptions are linked, since they are throw one after another and contain the same inner exception.
On the page that these exceptions are thrown, I use the WPToolkit plus some custom controls. Just LoopingSelector uses the Duration structure. But I see nothing wrong the code of the LoopingSelector.
Could somebody point in which direction to look for bugs? XAML Bindings? Casting?
It seems that I was able to find out a way around this issue.
In some cases the SSME.NaturalDuration.TimeSpan can be null. For those cases the NaturalDuration property has a flag HasTimeSpan, which returns false when the TimeSpan value cannot be retrieved.
So, I moved the binding logic to code behind. I check for SSME.NaturalDuration.HasTimeSpan always before setting a binding.