We have an application written in Delphi 6 in which we generate and execute machine code for maths operations (Input a string -> output machine code -> invoke lots and lots of times). This has been working well for many (many) years.
We recently added some functionality written in C# and accessed via COM. Accessing the new functionality works fine.
If there is an error in the calculation (say out of range or, div by 0) we are having problems.
If we have not created an instance of the COM object [ Note: we are not using the COM object here, only calling CreateOleObject()
to create it], and then input an invalid calculation (say, '1/0') we get an exception that we can trap and deal with.
However, once we have created the COM object we no longer get the Div/0 exception.
- First time we invoke it, we get a StackOverflow exception.
- Second time we invoke it, we get an Access Violation exception that cannot be trapped and causes the application to crash.
- As long as there is no error in the calculation, it executes correctly.
- As long as there is no COM object created, we can invoke the invalid calculation as many times as we like and just get the Div/0 error each time
- The COM object has nothing to do with the calculations and is never invoked, it seems to be merely creating it causes the problem
- The target machine has .NET 4 Client Profile and .NET 4 Extended frameworks installed
I recognize that this is pretty far out there in terms of usage but if anyone out there has any ideas I would appreciate the help. Thanks.
Update:
It turns out that we use other .Net assemblies in the application, accessing them through COM and that they do not cause a problem. I have created 2 simple assemblies, and made them COM accessible. One targets .Net 2.0 (N2), the other .Net 4.0 (N4). They both contain the same GetMessage()
function to return a string.
They are both registered using the .Net 4 regasm (.Net 2 regasm doesn't recognise the 4 assembly as being valid). If I create an instance of the N2 COM object all it good but creating an instance of the N4 COM object causes the bad behaviour. In neither case to I invoke GetMessage()
, I just create the COM object.
Update:
It seems that the problem is .Net Version related.
On a machine with .Net 4.0 Client, the div/0 gives a stack overflow exception and then (on the second call) crashes.
On a machine with .Net 4.5.1, I get a div/0 exception and everything is working fine.
Any ideas out there what might be different between how 4.5.1 and 4.0 (client) handle math co-processor exceptions?