Posted by
Luigi Ballabio on
Feb 07, 2012; 2:29pm
URL: http://quantlib.414.s1.nabble.com/NET-Framework-4-0-Application-Runtime-Exceptions-Problem-tp8685p8686.html
On Tue, Feb 7, 2012 at 6:03 AM, sergvil <
[hidden email]> wrote:
> 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 [...] pInvokeStackImbalance
Hi Sergvil,
it looks like you're not the only one having this issue. I
haven't tried it myself, as I don't use C#; but it looks like we have
a bug report for this on Sourceforge:
<
http://sourceforge.net/tracker/?func=detail&atid=112740&aid=3466468&group_id=12740>.
The good news is, I was sent a patch recently. I'm quoting it below;
let me know if it works for you, and I'll try to add it to the
repository (in some way I haven't yet found, since it seems to involve
either modifying SWIG or patching the generated code).
Later,
Luigi
On Tue, Jan 24, 2012 at 4:22 PM, Mark Gillis <...redacted...> wrote:
> Ahmad’s instructions are very good here:
>
http://stackoverflow.com/questions/3334011/compiling-quantlib-via-swig-for-c-sharp,
> which gets you most of the way, but there are some issues when you try to do
> this on VS 2010 and on Windows 7. Thought I would address those.
>
> First off, I did this all for QuantLib 1.2. After following Ahmad’s
> instructions above, and getting the completed files etc, and you go to run
> it in your own C# program you get this really nasty error
> “pInvokeStackImbalance error” (see BigChief’s comment on Ahmad’s post in
> the link above).
>
> This fun one took me a while to figure out, but think I’ve got it nailed
> down. Its caused by the SWIG conversion from C++ -> C#. The wrappers that
> SWIG creates doesn’t take into account the correct Calling Conventions into
> account. The C++ side thinks C# is going to clean up the stack, and the C#
> side thinks the C++ side will clean up the stack, and you end up with this
> ridiculous memory issue when calling any QuantLib methods.
>
> To fix :
>
> 1) Include windows.i file (found in original SWIG download) into the
> QuantLib-SWIG folder where the .i files are stored before you run SWIG on
> the whole QuantLib folder (as described by Ahmad).
>
> 2) In the resulting C++ SWIG files, somewhere in there is one that
> says “# define SWIGSTDCALL __stdcall” Replace __stdcall with __cdecl (note
> that’s two underscores)
>
> 3) In the C# side, where all the wrappers are defined with
> [DllImport…], add to each one (use a quick find and replace) the
> CallingConvention = CallingConvention.Cdecl
>
> 4) This should all build correctly now, just as in Ahmad’s
> instructions.
>
> Note that I’ve only just done this so I haven’t had a chance to test a lot
> of functionality (beyond now it doesn’t blow up if you try anything), but
> figure it’s a step in the right direction.
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users