I am writing an MC++ mixed-mode assembly (C++ and MC++) that will wrap
all TAO CORBA operations so that I can incorporate TAO into a C#
application. I am constrained to use TAO by the customer, so I can't
use IIOP.NET. I am constrained by the project to use C#, so I can't
use C++.
I am using VS.NET 2003, TAO 1.3a, Win2k sp4.
I have an interesting issue. The TAO IDL compiler emits these
"Remote_Proxy_Broker" classes for each client-side interface. These
classes each contain a "Factory Member function Implementation" of the
form:
_TAO_MyInterface_Remote_Proxy_Broker *
_TAO_MyInterface_Remote_Proxy_Broker::the_TAO_MyInterface_Remote_Proxy_Broker()
{
static ::_TAO_MyInterface_Remote_Proxy_Broker remote_proxy_broker;
return remote_proxy_broker;
}
Simple enough. The method, which is static, declares a static instance
of its type, and returns it when called. A singleton, in other words.
The problem is that my application crashes when trying to execute (i.e.
construct) the static instance. The exception is a
System.NullReferenceException. The call stack is something like:
msvcr71.dll __dllonexit
mydll.dll _onexit
mydll.dll atexit
mscorwks.dll 7925de73
I can get around this problem by modifying the code and making it a
more traditional singleton, where the method declares a static pointer
to an instance, and news it if the pointer is NULL. But this involves
hand-modifying code emitted by the TAO IDL compiler, and I am loath to
do this.
Even more fun, I found an example on the web
(http://kristopherjohnson.net/cgi-bin/twiki/view/KJ/ManagedChat) that
does the same thing with a simpler CORBA interface, and his code works
fine.
Any clues? I have read KB 814472, which seems to say that statics in a
mixed mode DLL, which is what I have, is a very bad idea and the
statics don't get initialized properly by default. But Kris Johnson's
example works.
Thanks.
reilly.
reilly - 14 Sep 2005 18:01 GMT
Of course, my post does contain a code error. The return statement
should be:
return &remote_proxy_broker;
Thanks.
reilly.