Login  Register

.NET Framework 4.0 Application Runtime Exceptions Problem

Posted by sergvil on Feb 07, 2012; 5:02am
URL: http://quantlib.414.s1.nabble.com/NET-Framework-4-0-Application-Runtime-Exceptions-Problem-tp8685.html

Hello,

I have been working with QuantLib since Oct'11 and I think it works great. I used it with .NET Framework 3.5 and it worked perfectly. I use QuantLib and SWIG for C#.

Now I am developing a .NET Framework 4 WPF application with some Quantlib Bond Calculations and I am having some problems:

When I make some testing, each time the app tries to create any QuantLib object or tries to execute any method it throws this exception (click on name for description):

pInvokeStackImbalance

When I try the application on Visual Studio and I have PInvolkeStackImbalance activated on MDA exceptions, I use to receive several PInvoke warnings (green coloured) on each execution, but the application works perfectly. But when I install and I try to execute on Windows, those warnings are exceptions that cause application to crash.

I tried to fix it making some modifications on QuantLib_vc10 project. I found at other forum this solution for the exception we are talking about:

On each dll method call defined on NQuantLibcPINVOKE that throws the exception, for example:

  [DllImport("NQuantLibc", EntryPoint="CSharp_new_TARGET")]
  public static extern IntPtr new_TARGET();


We can avoid the exception adding one parameter:

  [DllImport("NQuantLibc", EntryPoint="CSharp_new_TARGET", CallingConvention = CallingConvention.Cdecl)]
  public static extern IntPtr new_TARGET();


Using this, I can execute the app on Visual Studio with no warnings. But when app is installed on windows I receive other exception:

"The type initializer for 'QuantLib.NQuantLibcPINVOKE' threw an exception."

And the application crashes.


After trying this solution, now I have no idea how to fix it.

Is there any solution? Anybody knows how to compile QuantLib via SWIG in order to execute QuantLib Calculations on .NET Framework 4.0 applications?

If somebody has SWIG-QuantLib dlls (NQuantLib.dll and NQuantLibc.dll) compatible with .NET Framework 4.0 I would be so gratefull if I could receive them.

Thank you in advance.

Best Regards.

Sergio