The source of the problem is that there are AppDomains in the .Net world. An
AppDomain is a light-weight process. Every thread in the CLR lives in an
AppDomain. See
http://blogs.msdn.com/cbrumme/archive/2003/06/01/51466.aspxformore details.
Native C++ static variables does not know anything about AppDomains.
Therefore they should not be initialize in the code of managed compiled cpp
files. You can get by with this if your code is in the primary AppDomain.
This is not the case if you are writing an ASP.Net solution. In ASP.Net, the
Internet Information Server (IIS) is the primary AppDomain.
I came across the same problem went I wrote unit tests for my application.
Nunit.exe has the primary AppDomain and placed my tests in a secondary
AppDomain. The workaround I used is to set each QuantLib static variable in
a global function that uses "#pragma managed". See
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/cd3c34a6-84f9-4e2b-a483-12e179eb84b7Here is an example.
#pragma managed(push, off)
void SetQuantLibEvaluationDate(QuantLib::Date date)
{
QuantLib::Settings::instance().evaluationDate() = date;
}
#pragma managed(pop)
Since you are using ASP.Net, you should defined QL_ENABLE_SESSIONS and write
a Integer sessionID() function that returns an unique integer for each user.
Otherwise, all of your users will shared the same settings.
On Sat, Mar 6, 2010 at 7:02 PM, Cliffy <cfhgtwn@yahoo.com> wrote:
>
> Hi,
>
> I have a similar issue to this old thread -
>
>
>
http://old.nabble.com/Settings%3A%3Ainstance%28%29.evaluationDate%28%29-produces-exception-in-managed-code-to25479768.html#a25479768>
> I wrap quantlib.lib to a managed C++ dll and referenced it from an ASP.NET
> aspx web page in C#. It looks fine until it calls
> Settings::instance().evaluationDate().
>
> I have a different exception but I think the cause is the same -
>
> "The function must be called from the default domain"
>
> It fails in
> allocation a static variable in singleton.hpp
>
> static std::map<Integer, boost::shared_ptr<T> > instances_;
>
>
> template <class T>
> #if defined(QL_PATCH_MSVC) && defined(_MANAGED)
> inline // this seems to be required when CLR support is enabled
> #endif
> inline T& Singleton<T>::instance() {
> static std::map<Integer, boost::shared_ptr<T> > instances_;
>
> I did some search on the web, found some same issues but did not find any
> solutions.
> e.g.
>
>
>
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/cd3c34a6-84f9-4e2b-a483-12e179eb84b7>
> And there quite a few posts on the web about problems using static variable
> in unmanaged codes in a managed application.
>
> Anyone has success in implementing for quantlib as described? Or any
> suggestions are very apprecilated.
>
> Thanks
> --
> View this message in context:
>
http://old.nabble.com/Any-soultions-to-this-old-thread-of-calling-quantlib-from-managed-code--tp27808812p27808812.html> Sent from the quantlib-users mailing list archive at Nabble.com.
>
>
>
> ------------------------------------------------------------------------------
> Download IntelĀ® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
>
http://p.sf.net/sfu/intel-sw-dev> _______________________________________________
> QuantLib-users mailing list
> QuantLib-users@lists.sourceforge.net
>
https://lists.sourceforge.net/lists/listinfo/quantlib-users>
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev_______________________________________________
QuantLib-users mailing list
QuantLib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib-users