I have been developing an add on with C# and WPF to an application.
It's been working fine until launched on a Win7 machine. The symptoms are that a Microsoft .NET Framwork's "Unhandled exception" dialog pops up on startup for System.ArithmeticException (Overflow or underflow in the arithmetic operation) and gives a stack trace pointing to System.Windows.Controls.Primitives.Track.ComputeScrollBarLengths (...) and deeper.
So, I began to debug the app: it showed that System.ArithmeticException was thrown when setParent from user32.dll was called. This is done when the application makes a call to show the add-on UI.
public bool ShowUI(int Parent)
{
userControl = new MyUserControl(); // Extends System.Windows.Forms.UserControl
SetParent(userControl.Handle, new IntPtr(Parent)); // <- exception thrown here
...
}
What would possibly be causing this issue?
I'm adding the solution here in case someone finds it userful.
Something in the unmanaged code – only in the 64-bit version, though – caused the floating point operations to cause exceptions which caused this error, as mentioned in Hans Passant's comment. The solution was something similar to this answer: https://stackoverflow.com/a/19722292/8063451
Adding the
_fpreset()function call at the initialisation of my add-on solved the problem.