1

我希望StackOverflow上的某個人能幫我解決以下問題:我有一個WP7.1項目,我使用VS2012打開。另外,我已啓用公共語言運行時例外。通過這樣做,我想要捕捉並修復代碼中可能存在的大多數錯誤。公共語言運行時異常陷阱

當運行在模擬器中的項目,我得到了以下情況除外:

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以及一些自定義控件。 Just LoopingSelector使用持續時間結構。但是我沒看到任何錯誤的LoopingSelector的代碼。

難道有人指出尋找錯誤的方向? XAML綁定?鑄件?

+0

你是否綁定了任何TimeSpan或Duration屬性? –

+1

這是綁定中的錯誤,不能說更多。您可能能夠在輸出窗口中找到更多信息(當綁定失敗時,通常會顯示錯誤消息) –

+0

在我的xaml內我將SSME.NaturalDuration.TimeSpan值綁定到Slider.Maximum屬性。但TimeSpan通過一個Converter將TimeSpan轉換爲格式正確的字符串。 – Mike

回答

1

看來我能夠找到解決此問題的方法。

在某些情況下,SSME.NaturalDuration.TimeSpan可以爲空。對於這些情況,NaturalDuration財產有一個標記HasTimeSpan,當無法檢索TimeSpan值時返回false。

因此,我將綁定邏輯移到代碼後面。在設置綁定之前,我始終檢查是否有SSME.NaturalDuration.HasTimeSpan