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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:42:33+00:00 2026-05-11T06:42:33+00:00

I’d like to use an object across AppDomains. For this I can use the

  • 0

I’d like to use an object across AppDomains.

For this I can use the [Serializeable] attribute:

[Serializable] class MyClass {     public string GetSomeString() { return 'someString' } } 

Or subclass from MarshalByRefObject:

class MyClass: MarshalByRefObject {     public string GetSomeString() { return 'someString' } } 

In both cases I can use the class like this:

AppDomain appDomain = AppDomain.CreateDomain('AppDomain'); MyClass myObject = (MyClass)appDomain.CreateInstanceAndUnwrap(                    typeof(MyClass).Assembly.FullName,                    typeof(MyClass).FullName); Console.WriteLine(myObject.GetSomeString()); 

Why do both approaches seem to have the same effect? What is the difference in both approaches? When should I favor the one approach over the other?

EDIT: At the surface I know that there are differences between both mechanisms, but if someone jumped out of a bush and asked me the question I couldn’t give him a proper answer. The questions are quite open questions. I hoped that someone can explain it better than I could do.

  • 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. 2026-05-11T06:42:34+00:00Added an answer on May 11, 2026 at 6:42 am

    Using MarshallByRef will execute your methods in the remote AppDomain. When you use CreateInstanceAndUnwrap with a Serializable object, a copy of the object is made to the local AppDomain, so any method call will be executed in the local AppDomain.

    If what you want is to communicate between AppDomains go with the MarshallByRef approach.

    An example:

    using System; using System.Reflection;  [Serializable] public class SerializableClass {     public string WhatIsMyAppDomain()     {         return AppDomain.CurrentDomain.FriendlyName;     } }  public class MarshallByRefClass : MarshalByRefObject {     public string WhatIsMyAppDomain()     {         return AppDomain.CurrentDomain.FriendlyName;     } }      class Test {      static void Main(string[] args)     {         AppDomain ad = AppDomain.CreateDomain('OtherAppDomain');          MarshallByRefClass marshall = (MarshallByRefClass)ad.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, 'MarshallByRefClass');         SerializableClass serializable = (SerializableClass)ad.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, 'SerializableClass');          Console.WriteLine(marshall.WhatIsMyAppDomain());         Console.WriteLine(serializable.WhatIsMyAppDomain());      } } 

    This code will display ‘OtherAppDomain’ when you call WhatIsMyAppDomain from the MarshallByRef object, and your default AppDomain name when you call from the Serializable object.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
Does anyone know how can I replace this 2 symbol below from the string
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I want to count how many characters a certain string has in PHP, but

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.