.NET Framework Developer Center > .NET Framework Forums > Windows Presentation Foundation (WPF) > Argument Exception in TimeSpan internally in Dispatcher

Unanswered Argument Exception in TimeSpan internally in Dispatcher

  • Wednesday, March 04, 2009 9:32 AM
     
     
    Hi

    We are building a rather large application platform using WPF and are running into a very strange exception which causes our application to crash. We have no definitive way to reproduce it and cannot reproduce it in a smaller sample application, but the really annoying thing is that it seems very illogical to us.

    Let me give you some detail. We crash with the following stacktrace:

    [ArgumentException], "TimeSpan does not accept floating point Not-a-Number values."
       at System.TimeSpan.Interval(Double value, Int32 scale)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at XXX.ApplicationPlatform.Program.Main() in C:\projects\XXX\Source\ApplicationPlatform\ApplicationPlatform\Program.cs:line 98

    From this we conclude that we are not directly causing the exception, but we may be causing it indirectly. Looking into the Dispatcher.Invoke method using Reflector it seems that the following call fails, more specifically, the call internally to TimeSpan.FromMilliseconds:

     return this.InvokeImpl(priority, TimeSpan.FromMilliseconds(-1.0), method, this.CombineParameters(arg, args), false);

    We seems particularly strange to us is that this method is probably being called all the time withouot problems, to why does -1.0 al of a sudden become a NaN or at least, why does -1.0 return true in double.IsNaN?

    The application is multithreaded with lots of data being fetched async, but this exception does not seem to directly be runing in on of our async methods, it seems more like part of the wpf message pump (or equivalent)

    UPDATE: Forget to add these the first time. We also receive other strange "internal" exceptions related to timespans and the internals of the WPF messaging pump. These exception does not always seem to break our app, but are very strange and we would like to figure those out as well. Here are the stack traces we receive:

    ApplicationPlatform.vshost.exe Error: 0 : 2009-03-04 10:06:11: Exception[OverflowException]: TimeSpan overflowed because the duration is too long.
    StackTrace:    at System.TimeSpan.Subtract(TimeSpan ts)
       at System.Windows.Media.Animation.Clock.ComputeNextTickNeededTime(Nullable`1 expirationTime, TimeSpan parentTime, Double parentSpeed)
       at System.Windows.Media.Animation.Clock.ComputeLocalStateHelper(Boolean performTickOperations, Boolean seekedAlignedToLastTick)
       at System.Windows.Media.Animation.Clock.ComputeLocalState()
       at System.Windows.Media.Animation.ClockGroup.ComputeTreeState()
       at System.Windows.Media.Animation.TimeManager.Tick()
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
    InnerException:
    -

    ApplicationPlatform.vshost.exe Error: 0 : 2009-03-04 11:05:02: Exception[ArgumentException]: TimeSpan does not accept floating point Not-a-Number values.
    StackTrace:    at System.TimeSpan.Interval(Double value, Int32 scale)
       at System.Windows.Media.MediaContext.ScheduleNextRenderOp(TimeSpan minimumDelay)
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
    InnerException:
    -


    So somehow the internals get "screwed" up and it seems that the basic math being performed fails. Our fault? We don't know and can't seem to find out!

    Any input, ideas or comments that may help us debug these things would be greatly appreciated

    Soren
    • Edited by Enemaerke Wednesday, March 04, 2009 10:07 AM more stacktraces
    •  

All Replies

  • Monday, April 20, 2009 12:42 PM
     
     
    Did you ever find out the cause of this issue? This is occurring frequently in an application I am working with as well. Very annoying since there is no source to the problem!
  • Tuesday, April 21, 2009 2:12 AM
     
     
    I've got a little more feedback on this issue. This happens completely randomly at random intervals and has no identifiable reproduceable point in the application... ____, it doesn't even happen all the time. As I dug more deep into this issue, I found that if I disable the progress spinners in the application (they are little infinite progress indicators that are infinite doubleanimations) by not running the doubleanimation, this problem goes away (so far).

    There's nothing special about these animations as they are just like any other WPF animation and since this stacktrace doesn't give a specific source, I need to know what is causing it so I can fix it and turn my animations back on.

    Here's my stacktrace:

    ===================================

     

    Unhandled exception detected in application. Please see technical details for more information: UIElement.Measure(availableSize) cannot be called with NaN size.

     

    ===================================

     

    UIElement.Measure(availableSize) cannot be called with NaN size. (PresentationCore)

     

    ------------------------------

    Program Location:

     

       at System.Windows.UIElement.Measure(Size availableSize)

       at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

       at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

       at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Border.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Control.MeasureOverride(Size constraint)

       at Microsoft.Windows.Controls.DataGrid.MeasureOverride(Size availableSize)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

       at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Control.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

       at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

       at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Control.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

       at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Border.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.Controls.Page.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

       at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

       at System.Windows.UIElement.Measure(Size availableSize)

       at System.Windows.ContextLayoutManager.UpdateLayout()

       at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)

       at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()

       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()

       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)

       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)

       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

  • Tuesday, April 21, 2009 2:35 AM
     
     
    Same error, different source... this time with the animations off. I have now have no idea what's causing this:

     
    ===================================
     
    Unhandled exception detected in application. Please see technical details for more information: TimeSpan does not accept floating point Not-a-Number values.
     
    ===================================
     
    TimeSpan does not accept floating point Not-a-Number values. (mscorlib)
     
    ------------------------------
    Program Location:
     
       at System.TimeSpan.Interval(Double value, Int32 scale)
       at System.Windows.Media.MediaContext.ScheduleNextRenderOp(TimeSpan minimumDelay)
       at System.Windows.Media.MediaContext.EstimatedNextVSyncTimeExpired(Object sender, EventArgs e)
       at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
  • Wednesday, April 22, 2009 11:16 AM
     
     
    No unfortunately I didn't find a solution.

    Our best guess is that it is somehow related to the graphics driver of the machine, without us having a smoking gun pointing at a particular thing that triggers the behavior. What we saw was that on our development machines (DELL optiplex 960 with Radeon graphics cards) we could reproduce the issues under somewhat heacy data load/rendering, but on our target machines (don't have the specs here, sorry) none of these issues occured.

    Again, this is totally with evidence, but we found a few forum threads here and there that pointed to some issues with WPF and rendering problems on some graphics drivers. But it might be something else on our dev machines that caused the issue or we may have broken some unknown contract with the WPF rendering subsystem that we were unaware of...

    But our path ended where yours did: Issue happens in optimized code inside the BCL and we couldn't debug it or provide any reasonable repro of the situation in a small scaled down version. So, sorry, not much help here. We decided to move on and live with the weirdness since our target environment was not experiencing problems and we already spent way too much time digging around.

    Anybody from MS listening in that could give a clue as to how to further debug this issue for future reference?
  • Wednesday, April 22, 2009 9:39 PM
     
     
    We had a very similar experience! This problem only occurred on our development machines. It doesn't matter if we run with the debugger from the Visual Studio IDE or just run straight from the EXE... it will occur every time. This never occurred on any of our target environments (in our QA department or with beta testers). Because we were not able to reproduce this issue in QA, we have moved on as well and just sucked it up hoping it will not occur in the real world.

    It'd be even better if I could say that we have the same development machines as you do but we don't... we have DELL Latitude D830s with NVIDIA graphics cards. It would be great if someone from MS chimed in.
  • Thursday, October 14, 2010 3:29 PM
     
     

    I am also having the same issue on certain computers, with it being very hard to reproduce. Did you guys find any solution for this? Some of these WPF incompatabilities are very annoying.

     

     

    The stack trace is as follows:

    10/12/2010 5:32:06 PM UNHANDLED Global Exception Message TimeSpan does not accept floating point Not-a-Number values.

     

    10/12/2010 5:32:06 PM UNHANDLED Global Exception Inner Ex 

     

    10/12/2010 5:32:06 PM UNHANDLED Global Exception Stack Trace    at System.TimeSpan.Interval(Double value, Int32 scale)

       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

       at System.Windows.Threading.Dispatcher.Run()

       at System.Windows.Application.RunDispatcher(Object ignore)

       at System.Windows.Application.RunInternal(Window window)

       at System.Windows.Application.Run(Window window)

       at System.Windows.Application.Run()