none
System.ArithmeticException (Overflow or underflow in the arithmetic operation.)

    Question

  • im new to .net . today when i opened my application it gave an error saying
    "An unhandled exception of type 'System.ArithmeticException' occurred in system.drawing.dll

    Additional information: Overflow or underflow in the arithmetic operation."

    kindly please tell me how to remove it. i also searched it on net and i found the following that by changing the following code

    [STAThread]
    static void Main()
    {

    Application.Run(new Form1());
    }
    to

    [DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern int _controlfp(int n, int mask);

    [STAThread]
    static void Main()
    {
    const int _EM_OVERFLOW = 0x00000004;
    const int _MCW_EM = 0x0008001F;
    _controlfp(_EM_OVERFLOW, _MCW_EM);
    Application.Run(new Form1());
    }
    (the above cod eis from the foollowing link http://support.microsoft.com/default.aspx?scid=KB;EN-US;q326219)

    it will work but it stll gives an error to include the namespace or directive. so what namespace to be added .please help me in this regard how to remove also tell me what is the reason of this exceptionthis bug.the same error will occur even if i creat a new application and run an empty form that is a new form with no control on it . please help me

    thanx
    Friday, August 12, 2005 4:04 PM

Answers

  • Finally i've resolved the problem. I installed .NET on Xp SP1, but same result. I found in various forums that such an error is a reult of any other application/driver which is messing up with FPU. I installed a fresh XP pro, then without installing any other thing (no drivers) i installed .NET & run a form with few controls, it worked now. Then i put Intel  VGA driver, then sound driver, it remained working. When i installed motorola modem driver .NET again crashed with same error. Motorola modem driver had put a small sm56hlp icon in taskbar, i disabled that icon and also disableed its startup in msconfig. Now there is no error of system.drawing.dll.
    Monday, September 05, 2005 7:58 PM

All replies

  • Hi,

    Are you making calls to unmanaged code from your application? What does your application do. Please provide more details. If you are not making any unmanaged calls then this could be a valid overflow or underflow error due to someother operation in your code.

    Regards,
    Vikram
    Friday, August 12, 2005 7:07 PM
  • thanks fo rthe reply Vikram. but i get the same error each time i run dot whether it is C#.net or VB.net. even if i creat a new window application, a blnak form with no control on it and then run it it still gives that error. i have reinstalled dot net but still cant get the solution . please help me in this regard please
    Saturday, August 13, 2005 6:31 PM
  • Include name space System.Runtime.InteropServices and try out below code : --

    [DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern int _fpreset();

    [STAThread]
    static void Main()
    {
    _fpreset();
    Application.Run(new Form1());
    }
    Sunday, August 28, 2005 8:14 AM
  • Atif have u rectified your problem? i always got the error message
    "An unhandled exception of type 'System.ArithmeticException' occurred in system.drawing.dll

    Additional information: Overflow or underflow in the arithmetic operation."

    whenever i tried to run any application, even a single form with only one button. I have re-installed xp pro, reinstalled Visual studio 2003, updated VGA driver, nothing is in my favour. Is there anything wrong with processor etc?

    Sunday, September 04, 2005 7:53 PM
  • Finally i've resolved the problem. I installed .NET on Xp SP1, but same result. I found in various forums that such an error is a reult of any other application/driver which is messing up with FPU. I installed a fresh XP pro, then without installing any other thing (no drivers) i installed .NET & run a form with few controls, it worked now. Then i put Intel  VGA driver, then sound driver, it remained working. When i installed motorola modem driver .NET again crashed with same error. Motorola modem driver had put a small sm56hlp icon in taskbar, i disabled that icon and also disableed its startup in msconfig. Now there is no error of system.drawing.dll.
    Monday, September 05, 2005 7:58 PM
  • i repair the .net framework on the given machine. and still my application is not running on given machine , this problem is coming from last weak even this application work on another machine where also installed the same framework i.e., .net framework version 1.1 and on both machine Windows2000Server O.S. is installed. few days before this problem is comes on my machine at that time i repair .net framework and one my application is running but on another machine its not work pl give me some proper solution on it.

     

    Even i used this code also but still the same type of error come i.e.,Overflow or underflow an arithmatic exception

     

    [DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]

                public static extern int _controlfp(int n, int mask);
                [STAThread]
              
     static void Main() 
               
    { const int _EM_OVERFLOW = 0x00000004;
                
    const int _MCW_EM = 0x0008001F;
                 
    _controlfp(_EM_OVERFLOW, _MCW_EM);
                 
    Application.Run(new SplashForm());
              }

    Wednesday, October 04, 2006 9:42 AM
  • [DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern int _fpreset();

    [STAThread]
    static void Main()
    {
    _fpreset();
    Application.Run(new Form1());
    }

     

     

    Also if it’s not work then change dll that take msvcr72.dll

    Friday, November 24, 2006 3:54 AM
  • I also faced similar problem which gets resolved by doing _fpreset();. I was facing this on a  wpf application when uisng a 3rd party dll which uses unmanaged dll's internally. I want to know more about what could have caused this and is this a MS bug ?

    My details :

     

    My WPF test app (very simple, just one window) is using a 3rd party managed dll (say X.dll). This managed dll uses some unmanaged dll's . So lets say I write a small wpf app which just references X.dll. And in the window's constructor I access something inside X.dll (ie. in some namespace in X.dll). On doing this i dont catch any exception and it seems like things are going on as expected. But upon returning the control to .NET runtime, I get an exception in Application class's 'DispatcherUnhandledException' handler :

    “Overflow or underflow in the arithmetic operation.” System.ArithmeticException was unhandledMessage="Overflow or underflow in the arithmetic operation."
    Source="PresentationFramework"
    StackTrace:

    System.Windows.Window.ValidateTopLeft(Double length)
    System.Windows.Window.CoerceTop(DependencyObject d, Object value) System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean skipBaseValueChecks)
    System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
    System.Windows.DependencyObject.CoerceValue(DependencyProperty dp) at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
    System.Windows.Window.CreateSourceWindowImpl() at System.Windows.Window.SafeCreateWindow() at System.Windows.Window.ShowHelper(Object booleanBox)
    System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
    System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

    Some points:

    • This only occurs in WPF app and not in winforms app.
    • This does not get caught in a try-catch. only in Application's DispatcherUnhandledException
    • This does not happen if I access X.dll's code inside the Window's 'Loaded' event, only happens in constructor.

     


    Monday, March 22, 2010 12:33 PM