sergvil | 7 Feb 06:03
Picon
Favicon

.NET Framework 4.0 Application Runtime Exceptions Problem


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):

http://msdn.microsoft.com/es-es/library/0htdy0k3%28v=vs.100%29.aspx
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 application works
perfectly. But when 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, like this:

  [DllImport("NQuantLibc", EntryPoint="CSharp_new_TARGET")]
(Continue reading)

Luigi Ballabio | 7 Feb 15:29
Picon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem

On Tue, Feb 7, 2012 at 6:03 AM, sergvil <sergvil <at> hotmail.com> 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.
(Continue reading)

sergvil | 7 Feb 17:08
Picon
Favicon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem


Hello Luigi,

Thanks for your help.

Unfortunately this fix doesn't work properly. I make all changes described
on Ahmad's post but application continues throwing this exception:

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

when it tries to create the first QuantLib object (Calendar cal = new
TARGET())

And then the application crashes. 

With new dlls I have no exceptions from MDA when I executing on Visual
Studio. (this is good)

Is there any other solution?

Thank you very much.

Sergio.
--

-- 
View this message in context: http://old.nabble.com/.NET-Framework-4.0-Application-Runtime-Exceptions-Problem-tp33276539p33279669.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
(Continue reading)

sergvil | 8 Feb 03:06
Picon
Favicon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem


Thank you very much!!

The fix works!!

I sent you a previous message saying that it didn't work but I forgot to
apply one of the changes described on Ahmad's post.

Now it works perfectly. You can add this fix to QuantLib, it will be very
usefull for Framework 4.0 developers.

Thank you again!!

Best Regards.

Sergio
--

-- 
View this message in context: http://old.nabble.com/.NET-Framework-4.0-Application-Runtime-Exceptions-Problem-tp33276539p33283236.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
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
Ahmad Mahomed | 20 Feb 07:56
Picon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem

Hi  Sergio,


Can you please clarify which step  resolved your issue?

Ahmad

On 8 February 2012 04:06, sergvil <sergvil <at> hotmail.com> wrote:


Thank you very much!!

The fix works!!

I sent you a previous message saying that it didn't work but I forgot to
apply one of the changes described on Ahmad's post.

Now it works perfectly. You can add this fix to QuantLib, it will be very
usefull for Framework 4.0 developers.

Thank you again!!

Best Regards.

Sergio
--
View this message in context: http://old.nabble.com/.NET-Framework-4.0-Application-Runtime-Exceptions-Problem-tp33276539p33283236.html
Sent from the quantlib-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
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
QuantLib-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users



--
Ahmad Mahomed
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
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-dev2
_______________________________________________
QuantLib-users mailing list
QuantLib-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users
sergvil | 20 Feb 10:45
Picon
Favicon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem


Yes, the second one.

> 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) 

I forgot to change this code line the first time. After changing it, All
worked perfectly.

Ahmad Mahomed wrote:
> 
> Hi  Sergio,
> 
> Can you please clarify which step  resolved your issue?
> 
> Ahmad
> 
> On 8 February 2012 04:06, sergvil <sergvil <at> hotmail.com> wrote:
> 
>>
>>
>> Thank you very much!!
>>
>> The fix works!!
>>
>> I sent you a previous message saying that it didn't work but I forgot to
>> apply one of the changes described on Ahmad's post.
>>
>> Now it works perfectly. You can add this fix to QuantLib, it will be very
>> usefull for Framework 4.0 developers.
>>
>> Thank you again!!
>>
>> Best Regards.
>>
>> Sergio
>> --
>> View this message in context:
>> http://old.nabble.com/.NET-Framework-4.0-Application-Runtime-Exceptions-Problem-tp33276539p33283236.html
>> Sent from the quantlib-users mailing list archive at Nabble.com.
>>
>>
>>
>> ------------------------------------------------------------------------------
>> 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
>> QuantLib-users <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>>
> 
> 
> 
> -- 
> Ahmad Mahomed
> 
> ------------------------------------------------------------------------------
> Try before you buy = See our experts in action!
> 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-dev2
> _______________________________________________
> QuantLib-users mailing list
> QuantLib-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
> 
> 

--

-- 
View this message in context: http://old.nabble.com/.NET-Framework-4.0-Application-Runtime-Exceptions-Problem-tp33276539p33355675.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
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-dev2
_______________________________________________
QuantLib-users mailing list
QuantLib-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users
kcross | 10 Mar 23:57
Picon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem


Hi All,

Glad my fix for .NET (the cdecl thing...) worked for you guys too.  I'm
encountered a bit of a stumbling block though... Everything works fine when
I create a new instance of everything, but if I try and update an object (ie
update a yield curve) I get a bunch of AccessViolationExceptions (whatever
they mean...)

I was wondering if you guys have experienced the same thing etc?  I have a
feeling that its something to do with multi-threading, and some garbage
collector is acting out of line somewhere, but its been a bit of a nightmare
to track...

-kcross

sergvil wrote:
> 
> 
> Yes, the second one.
> 
>> 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) 
> 
> I forgot to change this code line the first time. After changing it, All
> worked perfectly.
> 
> 
> 
> Ahmad Mahomed wrote:
>> 
>> Hi  Sergio,
>> 
>> Can you please clarify which step  resolved your issue?
>> 
>> Ahmad
>> 
>> On 8 February 2012 04:06, sergvil <sergvil <at> hotmail.com> wrote:
>> 
>>>
>>>
>>> Thank you very much!!
>>>
>>> The fix works!!
>>>
>>> I sent you a previous message saying that it didn't work but I forgot to
>>> apply one of the changes described on Ahmad's post.
>>>
>>> Now it works perfectly. You can add this fix to QuantLib, it will be
>>> very
>>> usefull for Framework 4.0 developers.
>>>
>>> Thank you again!!
>>>
>>> Best Regards.
>>>
>>> Sergio
>>> --
>>> View this message in context:
>>> http://old.nabble.com/.NET-Framework-4.0-Application-Runtime-Exceptions-Problem-tp33276539p33283236.html
>>> Sent from the quantlib-users mailing list archive at Nabble.com.
>> 
>> -- 
>> Ahmad Mahomed
>> 
>> 
>> 
> 
> 

--

-- 
View this message in context: http://old.nabble.com/.NET-Framework-4.0-Application-Runtime-Exceptions-Problem-tp33276539p33478988.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
QuantLib-users mailing list
QuantLib-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users
sergvil | 11 Mar 07:02
Picon
Favicon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem


Hello kcross

Can you specify your issue?

This kind of exceptions can be thrown due to different situations. 

Perhaps some example code can help to solve your problems.

Regards.
--

-- 
View this message in context: http://old.nabble.com/.NET-Framework-4.0-Application-Runtime-Exceptions-Problem-tp33276539p33479768.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
Luigi Ballabio | 11 Mar 09:31
Picon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem

May it be related to this?

<http://old.nabble.com/Issues-with-C--Swig-Bindings,-NUnit-and-Settings.instance%28%29.setEvaluationDate%28%29-td30549787.html>

Luigi

On Sat, Mar 10, 2012 at 11:57 PM, kcross <markgillis0 <at> gmail.com> wrote:
> Glad my fix for .NET (the cdecl thing...) worked for you guys too.  I'm
> encountered a bit of a stumbling block though... Everything works fine when
> I create a new instance of everything, but if I try and update an object (ie
> update a yield curve) I get a bunch of AccessViolationExceptions (whatever
> they mean...)
>
> I was wondering if you guys have experienced the same thing etc?  I have a
> feeling that its something to do with multi-threading, and some garbage
> collector is acting out of line somewhere, but its been a bit of a nightmare
> to track...
>

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
kcross | 12 Mar 02:32
Picon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem


Thanks for the link.  Unfortunately it turned out to be a user error in this
case...  I forgot to divide some swap rates by 100.... 

Do you know if there is a way to have the C# side catch the QuantLib
exceptions?  Even if I wrapped it in a try-catch block it wouldn't work.. 

Cheers

Luigi Ballabio wrote:
> 
> May it be related to this?
> 
> <http://old.nabble.com/Issues-with-C--Swig-Bindings,-NUnit-and-Settings.instance%28%29.setEvaluationDate%28%29-td30549787.html>
> 
> Luigi
> 
> 
> On Sat, Mar 10, 2012 at 11:57 PM, kcross <markgillis0 <at> gmail.com> wrote:
>> Glad my fix for .NET (the cdecl thing...) worked for you guys too.  I'm
>> encountered a bit of a stumbling block though... Everything works fine
>> when
>> I create a new instance of everything, but if I try and update an object
>> (ie
>> update a yield curve) I get a bunch of AccessViolationExceptions
>> (whatever
>> they mean...)
>>
>> I was wondering if you guys have experienced the same thing etc?  I have
>> a
>> feeling that its something to do with multi-threading, and some garbage
>> collector is acting out of line somewhere, but its been a bit of a
>> nightmare
>> to track...
>>
> 
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing 
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> QuantLib-users mailing list
> QuantLib-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
> 
> 

--

-- 
View this message in context: http://old.nabble.com/.NET-Framework-4.0-Application-Runtime-Exceptions-Problem-tp33276539p33483767.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
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-dev2
_______________________________________________
QuantLib-users mailing list
QuantLib-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Luigi Ballabio | 22 Mar 09:28
Picon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem

On Mon, Mar 12, 2012 at 2:32 AM, kcross <markgillis0 <at> gmail.com> wrote:
> Do you know if there is a way to have the C# side catch the QuantLib
> exceptions?  Even if I wrapped it in a try-catch block it wouldn't work..

The SWIG machinery should catch the C++ exception and convert it into a C# one.
Doesn't this work? What happens instead?

Luigi

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
Mark Gillis | 29 Mar 02:52
Picon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem

It doesn't seem to want to for some reason.... Any time the c++ dll throws an exception, all the c# side seems
to do is throw an AccessViolationException... Even when I throw the code into a try catch block.

Kcross

On Mar 22, 2012, at 4:28 AM, Luigi Ballabio <luigi.ballabio <at> gmail.com> wrote:

> On Mon, Mar 12, 2012 at 2:32 AM, kcross <markgillis0 <at> gmail.com> wrote:
>> Do you know if there is a way to have the C# side catch the QuantLib
>> exceptions?  Even if I wrapped it in a try-catch block it wouldn't work..
> 
> The SWIG machinery should catch the C++ exception and convert it into a C# one.
> Doesn't this work? What happens instead?
> 
> Luigi

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
Luigi Ballabio | 3 Apr 12:14
Picon

Re: .NET Framework 4.0 Application Runtime Exceptions Problem

May you check the wrapper code in quantlib_wrap.cpp?  There should be
a try/catch block around each call into QuantLib code that should trap
the exception and convert it into a C# one.  Maybe you can try
debugging that somehow?

Luigi

On Thu, Mar 29, 2012 at 2:52 AM, Mark Gillis <markgillis0 <at> gmail.com> wrote:
> It doesn't seem to want to for some reason.... Any time the c++ dll throws an exception, all the c# side seems
to do is throw an AccessViolationException... Even when I throw the code into a try catch block.
>
> Kcross
>
>
>
> On Mar 22, 2012, at 4:28 AM, Luigi Ballabio <luigi.ballabio <at> gmail.com> wrote:
>
>> On Mon, Mar 12, 2012 at 2:32 AM, kcross <markgillis0 <at> gmail.com> wrote:
>>> Do you know if there is a way to have the C# side catch the QuantLib
>>> exceptions?  Even if I wrapped it in a try-catch block it wouldn't work..
>>
>> The SWIG machinery should catch the C++ exception and convert it into a C# one.
>> Doesn't this work? What happens instead?
>>
>> Luigi

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev

Gmane