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.
(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.)
Edit: ExecutionContext.SuppressFlow
looks promising, but it doesn't appear to achieve the goal. The following prints "MyIdentity":
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
}