Howdy I'm having difficulty throwing any kind of exception from within secondary domain, and then catching it back in the primary domain (I'm writing a managed C++ assembly, Windows XP, Visual Studio .NE 2003) The function foo() runs in the primary domain, creates a child domain instantiates an object within this domain, invokes some member whic throws an exception, then discards the child domain __gc struct Remote : public MarshalByRefObjec .... Method(... /* Load() throws a 'BadImageFormatException' if i name a non-assembly the exception is correctly marshalled back to the client exceptio handler in foo(), and everything is hunky-dory...* Assembly::Load(... /* but if instead i construct the exception myself and throw it...* throw new BadImageFormatException(... /* ...the runtime (marshaller?) complains that the exception i missing certain data members like the Source, and generates a exception of its own..* } ..... foo( ... AppDomain* d = AppDomain::CreateDomain(S"...") tr Remote* r = (Remote*) d->CreateInstanceAndUnwrap(...) r->Method() catch (BadImageFormatException* e /* caught fine when 'e' thrown by Assembly::Load() * catch (Exception* e /* but end up here instead when thrown by me directly* __finall AppDomain::Unload(d) Here is a dump of the exception that i actually catch - any idea wha gives Many thanks ---------------------------------------- Server stack trace at System.Exception.get_Source( at System.Exception.get_Source( at System.Exception.GetObjectData(SerializationInfo info StreamingContext c ntext at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerial ze(Object obj, ISurrogateSelector surrogateSelector, StreamingContex context, erObjectInfoInit serObjectInfoInit, IFormatterConverter converter at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize( bject obj, ISurrogateSelector surrogateSelector, StreamingContex context, SerO jectInfoInit serObjectInfoInit, IFormatterConverter converter at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obj ct graph, Header[] inHeaders, __BinaryWriter serWriter, Boolea fCheck at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize( tream serializationStream, Object graph, Header[] headers, Boolea fCheck at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessag Parts(ArrayList argsToSerialize at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage..ctor(IMeth dReturnMessage mrm at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage.SmuggleIfPo sible(IMessage msg at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[ req tmBuff, SmuggledMethodCallMessage smuggledMcm SmuggledMethodReturnMessage& smu gledMrm at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatch( yte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm SmuggledMethodReturnMe sage& smuggledMrm Exception rethrown at [0] at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessag re Msg, IMessage retMsg at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData msgD ta, Int32 type at Mpl.Reader.ReadAttribute(String __unnamed000, Int3 __unnamed001 at ?GetModuleAttribute@Mpl@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V? allocator@D@2@@std@@V?$Substring@$$CBD@@W4module_attribute@1@@Z(basic_string<ch r,std::char_traits<char>,std::allocator<char>>* , Substring<cha const > __unn med000, Int32 __unnamed001)}} {mnemonic {clr_exception}} {subsyste {clr}} {det ils {{System.NullReferenceException: Object reference not set to a instance o an object Server stack trace at System.Exception.get_Source( at System.Exception.get_Source( at System.Exception.GetObjectData(SerializationInfo info StreamingContext c ntext at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerial ze(Object obj, ISurrogateSelector surrogateSelector, StreamingContex context, S erObjectInfoInit serObjectInfoInit, IFormatterConverter converter) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(O bject obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerOb jectInfoInit serObjectInfoInit, IFormatterConverter converter) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obje ct graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S tream serializationStream, Object graph, Header[] headers, Boolean fCheck) at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessage Parts(ArrayList argsToSerialize) at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage..ctor(IMetho dReturnMessage mrm) at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage.SmuggleIfPos sible(IMessage msg) at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqS tmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smug gledMrm) at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatch(B yte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMes sage& smuggledMrm) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req Msg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa ta, Int32 type) at Mpl.Reader.ReadAttribute(String __unnamed000, Int32 __unnamed001) at ?GetModuleAttribute@Mpl@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$ allocator@D@2@@std@@V?$Substring@$$CBD@@W4module_attribute@1@@Z(basic_string<cha r,std::char_traits<char>,std::allocator<char>>* , Substring<char const > __unna med000, Int32 __unnamed001)}}}
It looks like the serialization that goes on as the exception gets marshaled across into the other domain calls the Source property, which is lazily initialized, and the lazy initialization is nullref'ing. Unfortunately, I couldn't reproduce your problem locally on .NET v1.1--what version are you using? Does this happen for all exceptions? Or just BadImageFormat? To try to narrow things down a bit, can you try something like: Exception *ex = new BadImageFormatException(...); ex->get_Source(); throw ex; That would cause the initialization to happen sooner. (You shouldn't have to do that; I'm just trying things out to try to narrow down the problem.) Jonathan This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- | Thread-Topic: Throwing exception from a child domain. | thread-index: AcRBqFMrtoKia3w0SJueuv62VK5knw== | X-WN-Post: microsoft.public.dotnet.framework.clr | From: "=?Utf-8?B?Sm9uYXRob24gQmVsbA==?=" <jbell@mathsoft.com> | Subject: Throwing exception from a child domain. | Date: Mon, 24 May 2004 09:01:07 -0700 | Lines: 167 | Message-ID: <5D41B1DF-91A3-4167-A045-DD6136BBFED6@microsoft.com> | MIME-Version: 1.0 | Content-Type: text/plain; | charset="Utf-8" | Content-Transfer-Encoding: 7bit | X-Newsreader: Microsoft CDO for Windows 2000 | Content-Class: urn:content-classes:message | Importance: normal | Priority: normal | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | Newsgroups: microsoft.public.dotnet.framework.clr | Path: cpmsftngxa10.phx.gbl | Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.clr:10690 | NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180 | X-Tomcat-NG: microsoft.public.dotnet.framework.clr | | Howdy, I'm having difficulty throwing any kind of exception from within a secondary domain, and then catching it back in the primary domain. (I'm writing a managed C++ assembly, Windows XP, Visual Studio .NET 2003). The function foo() runs in the primary domain, creates a child domain, instantiates an object within this domain, invokes some member which throws an exception, then discards the child domain: __gc struct Remote : public MarshalByRefObject { .... Method(...) { /* Load() throws a 'BadImageFormatException' if i name a non-assembly, the exception is correctly marshalled back to the client exception handler in foo(), and everything is hunky-dory...*/ Assembly::Load(...) /* but if instead i construct the exception myself and throw it...*/ throw new BadImageFormatException(...) /* ...the runtime (marshaller?) complains that the exception is missing certain data members like the Source, and generates an exception of its own..*/ } }; ..... foo( ... ) { AppDomain* d = AppDomain::CreateDomain(S"..."); try { Remote* r = (Remote*) d->CreateInstanceAndUnwrap(...); r->Method(); } catch (BadImageFormatException* e) { /* caught fine when 'e' thrown by Assembly::Load() */ } catch (Exception* e) { /* but end up here instead when thrown by me directly*/ } __finally { AppDomain::Unload(d); } } Here is a dump of the exception that i actually catch - any idea what gives? Many thanks, ----------------------------------------- Server stack trace: at System.Exception.get_Source() at System.Exception.get_Source() at System.Exception.GetObjectData(SerializationInfo info, StreamingContext co ntext) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSeriali ze(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, S erObjectInfoInit serObjectInfoInit, IFormatterConverter converter) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(O bject obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerOb jectInfoInit serObjectInfoInit, IFormatterConverter converter) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obje ct graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S tream serializationStream, Object graph, Header[] headers, Boolean fCheck) at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessage Parts(ArrayList argsToSerialize) at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage..ctor(IMetho dReturnMessage mrm) at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage.SmuggleIfPos sible(IMessage msg) at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqS tmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smug gledMrm) at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatch(B yte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMes sage& smuggledMrm) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req Msg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa ta, Int32 type) at Mpl.Reader.ReadAttribute(String __unnamed000, Int32 __unnamed001) at ?GetModuleAttribute@Mpl@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$ allocator@D@2@@std@@V?$Substring@$$CBD@@W4module_attribute@1@@Z(basic_string <cha r,std::char_traits<char>,std::allocator<char>>* , Substring<char const > __unna med000, Int32 __unnamed001)}} {mnemonic {clr_exception}} {subsystem {clr}} {deta ils {{System.NullReferenceException: Object reference not set to an instance of an object. Server stack trace: at System.Exception.get_Source() at System.Exception.get_Source() at System.Exception.GetObjectData(SerializationInfo info, StreamingContext co ntext) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSeriali ze(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, S erObjectInfoInit serObjectInfoInit, IFormatterConverter converter) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(O bject obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerOb jectInfoInit serObjectInfoInit, IFormatterConverter converter) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Obje ct graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(S tream serializationStream, Object graph, Header[] headers, Boolean fCheck) at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessage Parts(ArrayList argsToSerialize) at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage..ctor(IMetho dReturnMessage mrm) at System.Runtime.Remoting.Messaging.SmuggledMethodReturnMessage.SmuggleIfPos sible(IMessage msg)
Don't see what you're looking for? Try a search.
|