Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8242717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:15:41+00:00 2026-06-07T21:15:41+00:00

Does anyone if it’s possible to stop the current thread’s IPrincipal from propagating over

  • 0

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
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:15:44+00:00Added an answer on June 7, 2026 at 9:15 pm

    You didn’t run an asynchronous method, the target function is executed in the secondary appdomain by the same thread. So the principal doesn’t change. This works:

            var flow = ExecutionContext.SuppressFlow();
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("MyIdentity"), "Role".Split());
            ThreadPool.QueueUserWorkItem((x) => {
                AppDomain.CreateDomain("New domain").DoCallBack(Isolated);
            });
            flow.Undo();
    

    Or if you just want to run the same thread with a specific context then you can use ExecutionContext.Run():

            var copy = ExecutionContext.Capture();
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("MyIdentity"), "Role".Split());
            ExecutionContext.Run(copy, new ContextCallback((x) => {
                AppDomain.CreateDomain("New domain").DoCallBack(Isolated);
            }), null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to make this code stop the knob from rotating past
Does anyone have a sample application which makes use of mapping models in particular
Does anyone know how to access the contacts from the Galaxy S? I have
Does anyone have any idea if CloudFoundry is based on IaaS and datacenters from
Does anyone have a translate function for x/y positions after rotation in javascript? for
Does anyone know why UsernameExists wont return True. I must have my syntax messed
Does anyone have an example code for a join,changenick, ...etc functions calls in Strophe
Does anyone have any idea to track event of google analytics programatically in asp.net?
Does anyone have any suggestions for the best / simplest way to view all
Does anyone know how I can directly access a function from a PHP class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.