I came across a very strange exception. Cannot create instance of ‘ScrollViewer’ defined in assembly ‘PresentationFramework, Version=220.127.116.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35’. The type initializer for ‘System.Windows.Controls.ScrollViewer’ threw an exception. Overflow or underflow in the arithmetic operation I was not doing any calculations so I knew it was not part of my application but yet is caused one of my applications to crash as soon as its executed from another application.
Context: Im busy building a UI that must be displayed from our current C# application and from our legacy Delphi application. I created a com interface for the .Net assembly which then is used by the Delphi application as a normal com object.
The problem came when we created a test application that called the method that was exposed by the com interface. As soon as the method was executed I got the following error: ‘Maximized’ value cannot be assigned to property ‘WindowState’ of object ‘Project.SomeView’. Overflow or underflow in the arithmetic operation.
While debugging the problem I found the root cause was the Overflow or underflow in the arithmetic operation exception. This exception came from inside the Microsoft PresentationFramework assembly I did not know what to do (Ive never seen anything like this) so as any other developer would I fired up Firefox and goggled Overflow or underflow in the arithmetic operation exception
I found a post that had the code below but it was completely unrelated to WPF or Delphi.
While looking at the code I thought to myself that sure cant be the answer to the problem Im having. But decided to implement the function in any case just to see what will happen.
[DllImport( “msvcr70.dll”, CallingConvention = CallingConvention.Cdecl )]
public static extern int _fpreset();
I did some research on the API and found that it resets the floating point package. More information about the API can be found here. In my constructor just before the InitializeComponent() method I’ve added the following line
// Reset the Floating Point
So in the end my constructor looked like this:
// Reset the Floating Point (When called from External Application there was an Overflow exception)
// Initialize the Component
Hope this helps anyone in the future.