title: How expensive is using MarshalByRefObject compared to serialization?
body: <p>In my Azure web role code I have a <code>CustomIdentity</code> class derived from <code>System.Security.Principal.IIdentity</code>. At some point .NET runtime <a href="https://stackoverflow.com/q/6492762/57428">tries to serialize that class</a> and <a href="https://stackoverflow.com/q/6493371/57428">serialization wouldn't work</a>. Trying to resolve that I searched a lot and found <a href="https://stackoverflow.com/questions/1884030/implementing-a-custom-identity-and-iprincipal-in-mvc/3214178#3214178">this answer</a> and tried to inherit my class from <a href="https://stackoverflow.com/q/4295894/57428"><code>MarshalByRefObject</code></a>.</p>
  
  <p>Now once my <code>CustomIdentity</code> class inherits from <code>MarshalByRefObject</code> there're no serialization attempts anymore and my code works. However I'd like to know the performance implications of using <code>MarshalByRefObject</code> class.</p>
  
  <p>My code runs like this. First the request comes to IIS and is passed to the authentication code that creates an instance of <code>CustomIdentity</code> and attaches that instance to HTTP context. Then some time later the same HTTP context is passed to the ASP.NET handler that accesses that <code>CustomIdentity</code> instance at most once. The <code>CustomIdentity</code> object lives for the duration of request and is then destroyed.</p>
  
  <p>Now with serialization my <code>CustomIdentity</code> would be serialized into a stream, then deserialized from that stream into a new object. With <code>MarshalByRefObject</code> there's no serialization but a proxy is created and the access will be marshaled via RPC to where the actual object resides.</p>
  
  <p>How expensive will using <code>MarshalByRefObject</code> be in this scenario? Which - <code>MarshalByRefObject</code> or serialization - will be more costly?</p>