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

ASP.NET
ASP.NET(C#)
ASP.NET入门数据篇
C#Web应用程序入门经典学习笔记之一
ASP.NET2.0 WebRource,开发微调按钮控件
介绍几个ASP.NET中容易忽略但却很重要的方法函数
ASP.Net2.0 GridView 多列排序,显示排序图标,分页
ASP.NET 2.0 中的创建母版页
asp,asp.net学习教程下载
ASP.Net生成一个简单的图片
FCKeditor.Net_2.2安全修正版
ASP.NET与数据库相关技巧
在asp.net下实现Option条目中填充前导空格的方法
在ASP.NET中用MSDNURLRewriting实现Url Rewriting
在ASP.NET中实现多文件上传的方法
Community Server专题二:体系结构
在ASP.NET中重写URL的代码
asp.net下大文件上传知识整理
ASP.NET中常用的三十三种代码
asp.net下实现支持文件分块多点异步上传的 Web Services
ASP.NET 2.0,C#----图像特效处理

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 165 ::
收藏到网摘: 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&