Wednesday, February 22, 2012

When CLR JIT meets floating overflow exceptions

 

Last year, one of my colleagues met a weird problem: the managed dlls he developed throw exception when integrated into one version of a CAD system --- MicroStation, while worked well for all other versions. The exception says about float overflow exception.

Then, after investigating the root reason, it is said that CLR JIT needs the floating overflow exception to be masked away, while this flag may be enabled by some applications, especially when developing some SDK in c#, integrating them into some old hosting application, and it may cause trouble.

The http://social.msdn.microsoft.com/Forums/en/clr/thread/b3505262-4e01-4e21-bea6-ce897caf4186 also talks about a similar case.

To fix the problem we can simple call

   1: _control87(MCW_EM, MCW_EM);

to mask away the related flags at the entry point of our SDK dll.

No comments:

Post a Comment