-1

Problem: System.ArgumentOutOfRangeException: Der TimeSpan-Zeitraum muss kleiner oder gleich "Int32.MaxValue" sein. (value must be smaller or equal "Int32.MaxValue")

Stacktrace:

bei System.Windows.Threading.DispatcherTimer.set_Interval(TimeSpan value) bei System.Windows.Controls.PopupControlService.ShowToolTip(DependencyObject o, Boolean fromKeyboard) bei System.Windows.Controls.PopupControlService.PromotePendingToolTipToCurrent(TriggerAction triggerAction) bei System.Windows.Controls.PopupControlService.<>c__DisplayClass15_0.b__0(Object s, EventArgs e) bei System.Windows.Threading.DispatcherTimer.FireTick(Object unused) bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Analysis:

Exception is thrown here: if (value.TotalMilliseconds > Int32.MaxValue) throw new ArgumentOutOfRangeException("value", SR.TimeSpanPeriodOutOfRange_TooLarge); where value is a TimeSpan https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherTimer.cs#L154

The value [TimeSpan] is created here:

CurrentToolTipTimer.Interval = TimeSpan.FromMilliseconds(ToolTipService.GetShowDuration(o)); https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs#L477

ToolTipService.GetShowDuration(o) returns an int

This leads to the following: 'TimeSpan.FromMilliseconds(x).TotalMilliseconds > int.MaxValue' must be true

What value can x have that the exception is thrown?

** Reformulated the question because it lead to some misunderstanding. ** I don't know which of my code or third party code is relevant, that the exception is thrown. The error is not reproducable and happend 3-4 times on a program that is used on several thousand clients for several hours per day.

  • it isn't: https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEUCuA7AHwAEAmARgFgAoANwEMoACBRxgXkYBUBLAWxgDKABzp4AdADEoEXgFluAGwXcAzjEh4AJioAU3PBjGy6CAGp0FOGAEoA3NSJkAnHoNGT5yzftVHLhGKcEBgW8kqq6hBaKnYOzjoBQSEKYcpqGtqMAHyM+obGZhZWdkA=== - so... something else must be happening – Marc Gravell Oct 12 '22 at 12:28
  • 1
    `TotalMilliseconds` is a `double` and can easily be greater than `int.MaxValue`, especially if processing causes scaling issues. – Panagiotis Kanavos Oct 12 '22 at 12:29
  • 1
    What are you trying to do and what's the *actual* code that produces this problem? You aren't comparing a `Timespan` you created yourself with an integer. You're comparing something generated by `PopupControlService`. Why and how are you setting `int.MaxValue` ? – Panagiotis Kanavos Oct 12 '22 at 12:32
  • "_value must be bigger or smaller than Int32.MaxValue)_" What? –  Oct 12 '22 at 12:32
  • @PanagiotisKanavos Sure, but according to the stacktrace the passed value must be an integer. All function calls that are relevant can be seen in the stacktrace (and are all from the .net framework itself). – Benny Bürger Oct 12 '22 at 13:10
  • @Damien_The_Unbeliever Good point, I modified the links – Benny Bürger Oct 12 '22 at 13:10
  • @MySkullCaveIsADarkPlace Sorry, I modified the sentence – Benny Bürger Oct 12 '22 at 13:10
  • That's not what the stacktrace says. It doesn't say that something must be one type or the other - that's fixed at compile time. The control you tried to use expects a valid TimeSpan, not an infinite one. If you wanted to create a tooltip that doesn't close, you need a different control. The value you tried to use actually comes from a Dependency property. You still haven't posted the code that sets it, but somewhere between that code and `DispatcherTimer` that got rounded up – Panagiotis Kanavos Oct 12 '22 at 13:15
  • BTW and FYI, your stack trace doesn't seem to be from .NET Framework 4.8. According to the 4.8 sources for PopupControlService available here: https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/PopupControlService.cs, PopupControlService doesn't have a ShowToolTip method. Whereas the implementation for .NET Core/5/6/... does actually feature a ShowToolTip method: https://source.dot.net/#PresentationFramework/System/Windows/Controls/PopupControlService.cs –  Oct 12 '22 at 13:17
  • @BennyBürger did you try to use the *wrong* answers in [Forcing a WPF tooltip to stay on the screen](https://stackoverflow.com/questions/896574/forcing-a-wpf-tooltip-to-stay-on-the-screen)? Given that `PopupControlService` is open source you can simply copy the code and create your own *without the timeout timer at all*. Timers are a limited resource – Panagiotis Kanavos Oct 12 '22 at 13:17
  • @PanagiotisKanavos Yes the value comes from a DP and the DP always returns an integer value. I don't know which code leads to this exception, it is not reproducable and may even come from a third party library. That's why I tried to analyze the stacktracke, which should usually be enough to get to the root of the problem – Benny Bürger Oct 12 '22 at 13:28
  • @MySkullCaveIsADarkPlace Our application is targeting .NET Framework 4.8, so the stacktrace should be from .NET Framework 4.8 – Benny Bürger Oct 12 '22 at 13:29

1 Answers1

2

Microsoft has released a Windows update which shall resolve this problem:

Addresses an issue where opening a tooltip causes an ArgumentOutOfRangeException, when the app has changed the floating-point control word.

https://devblogs.microsoft.com/dotnet/dotnet-framework-october-2022-security-and-quality-rollup/

Peter S.
  • 36
  • 2
  • Thanks, I should've looked at the source code of the same revision in order to find this problem. But who expects a bug in the framework itself... – Benny Bürger Oct 27 '22 at 13:29