TypeInitializationException with QuantLib-SWIG 1.6 x64 for C#

Posted by grantathon on
URL: http://quantlib.414.s1.nabble.com/TypeInitializationException-with-QuantLib-SWIG-1-6-x64-for-C-tp16732.html

Hello,

I recently setup QuantLib-SWIG 1.6 for C# using the Visual Studio 2012 compiler (vc120), and I'm very happy that I can finally use QuantLib 1.6 in our Visual Studio 2013 C# solutions.  I'm able to run the BermudanSwaption and EquityOption examples under the Win32 platform in Debug and Release mode, but for the x64 platform I'm only able to run in Release mode.

The thing is, I need it to be able to run in Debug mode when using the x64 platform.  Unfortunately, when running x64/Debug with debugging (F5) I get the following TypeInitializationException

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

and under the same settings without debugging (Ctrl+F5) I get

Unhandled Exception: System.TypeInitializationException: The type initializer for 'QuantLib.NQuantLibcPINVOKE' threw an
exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. -
--> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRES
ULT: 0x8007000B)
   at QuantLib.NQuantLibcPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_NQuantLibc(ExceptionDelegate applica
tionDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOf
RangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDe
legate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelega
te, ExceptionDelegate systemExceptionDelegate)
   at QuantLib.NQuantLibcPINVOKE.SWIGExceptionHelper..cctor() in c:\Program Files\QuantLib\QuantLib-SWIG-1.6\CSharp\csha
rp\NQuantLibcPINVOKE.cs:line 105
   --- End of inner exception stack trace ---
   at QuantLib.NQuantLibcPINVOKE.SWIGExceptionHelper..ctor()
   at QuantLib.NQuantLibcPINVOKE..cctor() in c:\Program Files\QuantLib\QuantLib-SWIG-1.6\CSharp\csharp\NQuantLibcPINVOKE
.cs:line 125
   --- End of inner exception stack trace ---
   at QuantLib.NQuantLibcPINVOKE.new_Date__SWIG_1(Int32 jarg1, Int32 jarg2, Int32 jarg3)
   at QuantLib.Date..ctor(Int32 d, Month m, Int32 y) in c:\Program Files\QuantLib\QuantLib-SWIG-1.6\CSharp\csharp\Date.c
s:line 102
   at BermudanSwaption.Run.Main(String[] args) in c:\Program Files\QuantLib\QuantLib-SWIG-1.6\CSharp\examples\BermudanSw
aption.cs:line 72

I have read other solutions to this problem, like checking to see if the proper Library Dependencies are set and setting the platform properly, but these solutions didn't help as I have already implemented them.  I even rebuilt Boost and QuantLib 1.6 under the x64/Debug configurations, but this still didn't help.

Is there anyone that could help me out with this issue?  This is rather critical for me and I can't seem to figure it out.  I should be able to give you any other information you request.

Thanks in advance.