1

我希望 StackOverflow 上的人能帮助我解决以下问题:

我有一个使用 VS2012 打开的 WP7.1 项目。另外,我启用了公共语言运行时异常。通过这样做,我想捕捉并修复代码中可能存在的大多数错误。

在模拟器中运行项目时,出现以下异常:

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)

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)

显然这两个异常是相互关联的,因为它们一个接一个地抛出并且包含相同的内部异常。

在抛出这些异常的页面上,我使用了 WPToolkit 和一些自定义控件。只是 LoopingSelector 使用了 Duration 结构。但我认为 LoopingSelector 的代码没有错。

有人可以指出寻找错误的方向吗?XAML 绑定?铸件?

4

1 回答 1

1

似乎我能够找到解决此问题的方法。

在某些情况下,SSME.NaturalDuration.TimeSpan可以为空。对于这些情况,NaturalDuration属性有一个标志HasTimeSpan,当无法检索 TimeSpan 值时它返回 false。

因此,我将绑定逻辑移至代码后面。我总是在设置绑定之前检查SSME.NaturalDuration.HasTimeSpan 。

于 2013-01-08T11:43:55.737 回答