3

I'm working on my first project that uses AppDomains and I'm wondering what happens when an object derives from MarshalByRefObject and is also marked [Serializable]?

for example:

[Serializable]
public class DummyClass: MarshalByRefObject
{

}
mahoriR
  • 4,377
  • 3
  • 18
  • 27
  • It becomes serializable? What do you mean "what happens"? Did you read the documentation for those two items? – Cody Gray - on strike Jan 10 '12 at 06:05
  • 2
    @CodyGray: If you have ask about 'what happens?' then you are not intimately familiar with .NET remoting. – leppie Jan 10 '12 at 06:16
  • 2
    @Ravi: I think best is to set up a small server scenario and test it :) Perhaps being derived from `MarshalByRefObject` will 'veto' serializable. – leppie Jan 10 '12 at 06:19
  • @leppie It does indeed, though not by vetoing the serialisation, but by changing it. See my answer. – Jon Hanna Jan 10 '12 at 10:14

1 Answers1

1

It gets marshalled by reference, but can still be serialised for other use-cases for serialisation. There's an implementation detail to this that is interesting enough to be worth noting: The formatter that is serialising for remoting uses a SurrogateSelector that will produce a proxy for any MarshalByRefObject it serialises, hence serialising will still result in marshalling by reference. Other serialisation uses won't have that SurrogateSelector and so won't have that effect.

Jon Hanna
  • 110,372
  • 10
  • 146
  • 251
  • what is the meaning of marshalled here, can you elaborate please? – Ehsan Sajjad Dec 15 '15 at 17:18
  • @EhsanSajjad that's more a separate question than a comment on this question and answer. One that is perhaps duplicated at http://stackoverflow.com/questions/5600761/what-is-marshalling-what-is-happening-when-something-is-marshalled and certainly should be answerable by googling. – Jon Hanna Dec 15 '15 at 17:25
  • i asked few seconds ago: http://stackoverflow.com/questions/34295644/what-does-actually-marshalbyref-means – Ehsan Sajjad Dec 15 '15 at 17:26