当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > .Net中使用com组件后发生System.ArithmeticException异常的解决办法

ASP.NET
dotNET下面调用Access中存储过程的方法
DataSet 的 Merge 方法研究
C#中using关键字的使用
Visual C#程序设计技巧小结
Creating GUIDs in c#
C#覆盖虚接口
在C#中应用哈希表(Hashtable)
对C#泛型中的new()约束的一点思考
身份证15To18 的算法(C#)
ADO.NET的结构体系。
ADO.NET的DataSet和ADO的Recordset的比较
OpenGLStepbyS
.NET对软件安装的冲击
IsVS.NETreadyforenterprise?(1)
IsVS.NETreadyforenterprise?(5)
IsVS.NETreadyforenterprise?(6)
.Net和Java有何相似之处
Hi,现在我们暂时不谈Passport
替代System.Web.Mail的新类库(新增邮件列表功能)
C#和VB.NET的区别

ASP.NET 中的 .Net中使用com组件后发生System.ArithmeticException异常的解决办法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 133 ::
收藏到网摘: n/a


最近在开发一个.Net程序,其中涉及到对com组件的调用,在调用完以后如果使用一些小的测试程序继续运行,一切正常,但是在使用带有GUI的form程序继续执行时,总是出现以下异常Exception: System.ArithmeticExceptionMessage: 算术运算中发生溢出或下溢。Source: System.Drawing at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont) at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet) at Payment.Phone.ErrorForm.InitializeComponent() in E:\cvsroot\develope\payment\Phone\ErrorForm.cs:line 108 at Payment.Phone.ErrorForm..ctor(Util util, String msg) in E:\cvsroot\develope\payment\Phone\ErrorForm.cs:line 139 at Payment.Phone.ConfirmForm.lblNext_Click(Object sender, EventArgs e) in E:\cvsroot\develope\payment\Phone\ConfirmForm.cs:line 212
后来到处找资料,花了我一天的时间才给解决,以下是我的解决办法:1.声明一个DLL掉用 [DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)] unsafe public static extern int _controlfp(int n, int mask);2.在代码中添加以下代码方法 internal void ResetFPCR() { const int _EM_OVERFLOW = 0x0009001F; const int _MCW_EM = 0x000FFFFF; _controlfp(_EM_OVERFLOW, _MCW_EM); }3.在调用完com组件后,调用以上方法,如: //这里调用com组件 //然后执行Reset方法 ResetFPCR(); 注:具体详细请看http://support.microsoft.com/default.aspx?scid=KB;EN-US;q326219&