System.Drawing raises a System.ArithmeticException

A

Avi Farah

I do not know what I did to get this condition and hope
that someone can shed some light on it.

As of late I get a System.ArithmeticException raised by
the System.Drawing module. Steps to getting the
exception in VS.Net 2003 (and VS.Net 2002):

If I run an empty form I do not get the exception. By
empty form I mean that I start VS.Net request a "Windows
Application" in VB.Net or C# and then run the wizard
generated application (I get no exception).

If to the above application I drag a control (like a
textbox, or a button) from the Toolbox, then the
application throws the exception. This exception is
thrown in the InitializeComponent() function's 1st
line:

"this.textBox1 = new System.Windows.Forms.TextBox
();"

I get this exception also when I run programs that I ran
previously without a problem like the: "Microsoft .NET
Framework 1.1 Wizards" part of the Administrative Tools.
Or code provided by one of the .Net books.

I already reloaded VS but to no avail.

Any suggestions?

Many thanks,
Avi
 
A

Avi Farah

The problem is a bug floating point error. Resolution:

1 include: using System.Runtime.InteropServices;

2 Before the Main(..) function insert:
[DllImport("msvcr70.dll", CallingConvention =
CallingConvention.Cdecl)]
public static extern int _controlfp(int n, int mask);

3 First thing in Main() before Application.Run(new Form1
());
insert:
const int _RC_NEAR = 0x00000000;
const int _PC_53 = 0x00010000;
const int _EM_INVALID = 0x00000010;
const int _EM_ZERODIVIDE = 0x00000008;
const int _EM_OVERFLOW = 0x00000004;
const int _EM_UNDERFLOW = 0x00000002;
const int _EM_INEXACT = 0x00000001;
const int _EM_DENORMAL = 0x00080000;
const int _CW_DEFAULT = ( _RC_NEAR + _PC_53 + _EM_INVALID
+ _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW +
_EM_INEXACT + _EM_DENORMAL);
_controlfp(_CW_DEFAULT, 0xfffff);

Cheers,
Avi
 
A

Alex

I've just found this post and I'm having the same problem. Do you know
if there is an equivelent fix for Visual Basic as well?

Avi Farah said:
The problem is a bug floating point error. Resolution:

1 include: using System.Runtime.InteropServices;

2 Before the Main(..) function insert:
[DllImport("msvcr70.dll", CallingConvention =
CallingConvention.Cdecl)]
public static extern int _controlfp(int n, int mask);

3 First thing in Main() before Application.Run(new Form1
());
insert:
const int _RC_NEAR = 0x00000000;
const int _PC_53 = 0x00010000;
const int _EM_INVALID = 0x00000010;
const int _EM_ZERODIVIDE = 0x00000008;
const int _EM_OVERFLOW = 0x00000004;
const int _EM_UNDERFLOW = 0x00000002;
const int _EM_INEXACT = 0x00000001;
const int _EM_DENORMAL = 0x00080000;
const int _CW_DEFAULT = ( _RC_NEAR + _PC_53 + _EM_INVALID
+ _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW +
_EM_INEXACT + _EM_DENORMAL);
_controlfp(_CW_DEFAULT, 0xfffff);

Cheers,
Avi


-----Original Message-----
I do not know what I did to get this condition and hope
that someone can shed some light on it.

As of late I get a System.ArithmeticException raised by
the System.Drawing module. Steps to getting the
exception in VS.Net 2003 (and VS.Net 2002):

If I run an empty form I do not get the exception. By
empty form I mean that I start VS.Net request a "Windows
Application" in VB.Net or C# and then run the wizard
generated application (I get no exception).

If to the above application I drag a control (like a
textbox, or a button) from the Toolbox, then the
application throws the exception. This exception is
thrown in the InitializeComponent() function's 1st
line:

"this.textBox1 = new System.Windows.Forms.TextBox
();"

I get this exception also when I run programs that I ran
previously without a problem like the: "Microsoft .NET
Framework 1.1 Wizards" part of the Administrative Tools.
Or code provided by one of the .Net books.

I already reloaded VS but to no avail.

Any suggestions?

Many thanks,
Avi

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top