Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / June 2004

Tip: Looking for answers? Try searching our database.

Throwing exception from a child domain.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonathon Bell - 24 May 2004 17:01 GMT
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
Jonathan Keljo [MS] - 24 Jun 2004 21:44 GMT
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==
[quoted text clipped - 20 lines]
|
| 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)
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)}}}

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.