码迷,mamicode.com
首页 > Web开发 > 详细

.Net中使用com组件后发生System.ArithmeticException异常的解决办法(Message=算术运算中发生溢出或下溢。)

时间:2016-06-02 19:46:08      阅读:531      评论:0      收藏:0      [点我收藏+]

标签:

最近在开发一个.Net程序,其中涉及到对com组件的调用,或者第三方DLL调用,

在调用完以后如果使用一些小的测试程序继续运行,一切正常,但是在使用带有GUI的form程序,或者WPF程序中,继续执行时,总是出现以下异常Exception: System.ArithmeticExceptionMessage: 算术运算中发生溢出或下溢。

  “设置属性“System.Windows.FrameworkElement.Height”时引发了异常。”,行号为“6”,行位置为“14”。

在 System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
在 System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
在 System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
在 System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
在 Evidence.MVVM.Views.WinIdentityVeri.InitializeComponent() 位置 E:\Win.xaml:行号 1

解决方法:

1.声明一个DLL掉用

[DllImport("msvcr71.dll", CallingConvention = CallingConvention.Cdecl)]
       public static extern int _controlfp(int n, int mask);
       internal void ResetFPCR()
       {
           const int _EM_OVERFLOW = 0x0009001F;
           const int _MCW_EM = 0x000FFFFF;
           _controlfp(_EM_OVERFLOW, _MCW_EM);
       }

2.在调用完com组件后,调用以上方法,如:

//这里调用com组件

//然后执行Reset方法

ResetFPCR();

如果没有msvcr71.dll 从网上下载 然后放到bin目录下

.Net中使用com组件后发生System.ArithmeticException异常的解决办法(Message=算术运算中发生溢出或下溢。)

标签:

原文地址:http://www.cnblogs.com/z_lb/p/5553935.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!