title: Preventing Thread.CurrentPrincipal from propagating across application domains
body: <p>Does anyone if it's possible to stop the current thread's IPrincipal from propagating over an application domain boundary? I have no control over the IPrincipal that's assigned to the thread, but I do have control over creating the application domains.</p>
  
  <p>(The reason I want to do this is to prevent a serialization error from occuring if the principal object type's assembly is unavailable in the other domain.)</p>
  
  <p>Edit: <code>ExecutionContext.SuppressFlow</code> looks promising, but it doesn't appear to achieve the goal. The following prints "MyIdentity":</p>
  
  <pre><code>static void Main ()
  {
      ExecutionContext.SuppressFlow ();
      Thread.CurrentPrincipal = new GenericPrincipal (new GenericIdentity ("MyIdentity"), "Role".Split ());
      AppDomain.CreateDomain ("New domain").DoCallBack (Isolated);
  }
  
  static void Isolated ()
  {
      Console.WriteLine ("Current principal: " + Thread.CurrentPrincipal.Identity.Name);  // MyIdentity
  }
  </code></pre>