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 7193499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:10:56+00:00 2026-05-28T20:10:56+00:00

I create an AppDomain, create an instance of an object in the new Domain

  • 0

I create an AppDomain, create an instance of an object in the new Domain and call a method that returns the name of the current AppDomain on the wrapped object. the returned value is the name of the main program domain and not the newly created one. By the way the code is being executed as a UnitTest in VS2010.

Any Idea why the test fails?

[Serializable]
    public class DomainHelper
    {
        public string GetDomainName()
        {
            return AppDomain.CurrentDomain.FriendlyName;
        }
    }


    [TestClass]
    public class DomainTests
    {
        [TestMethod]
        public void RemoteCall()
        {
            var binDir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            const string appDomainName = "TEST";
            var x = AppDomain.CreateDomain(appDomainName, null, binDir,null, false);

            var remoteType = typeof(DomainHelper);
            var remote = (DomainHelper) x.CreateInstanceAndUnwrap(remoteType.Assembly.FullName, remoteType.FullName);

            Assert.AreEqual(appDomainName, remote.GetDomainName());
        }
    }
  • 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-05-28T20:10:58+00:00Added an answer on May 28, 2026 at 8:10 pm

    Because the DomainHelper is [Serializable]. Which means when it crosses domains, it is copied and recreated in the caller’s domain, and afterwards .GetDomainName is executed in the caller’s domain. You can either remove the [Serializable] attribute and have the DomainHelper derive from MarshalByRefObject, then the .GetDomainName would be executed in the remote domain, or keep the [Serializable] attribute and retrieve the domain name in a constructor or initializer, like so:

    [Serializable]
    public class DomainHelper
    {
        private readonly string _domainIWasConstructedIn = AppDomain.CurrentDomain.FriendlyName;
    
        public string GetDomainName()
        {
            return _domainIWasConstructedIn;
        }
    }
    

    The initializer/constructor would then execute in the remote domain, and the relevant fields it sets would be copied when the object crosses domains.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an instance of an object inside of an AppDomain.
Is it possible to create a new app domain and instantiate an instance of
Create a new appdomain, setup the assemblyResolve handler and you always get an exception
I have this class, instance of which I create in an AppDomain with no
I use the default appdomain (AD) which I use to create new appdomains (AD1)
In .Net we can create AppDomain by writing AppDomain domain = AppDomain.CreateDomain(MyDomain); My question
I have a service app that creates AppDomain's during the course of its use
I want to know if I can tell what appdomain a object was created
I have been working on test framework, which creates a new app domain to
create table person ( name varchar(15), attr1 varchar(15), attr2 varchar(1), attr3 char(1), attr4 int

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.