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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:46:51+00:00 2026-06-07T12:46:51+00:00

I have a section of code which is passing an object across AppDomains and

  • 0

I have a section of code which is passing an object across AppDomains and to make debugging easier I want to get rid of the TransparentProxy.

In the course of writing this sample, I discovered how to do it, but I have two very similar snippets of code which behave differently and I am not sure why.

I know the actuals values are correct, so this is just to aid debugging.

In the example below. I have a class Data which is initialised in the default domain and passed to Process which is running in another domain. If I attempt to clone the data structure using the static method it works, but using the instance method does and I don’t quite understand why.

Can anyone explain?

using System;

class Program
{
    static void Main(string[] args)
    {
        AppDomain otherDomain = AppDomain.CreateDomain("Test");

        var otherType = typeof(Process);
        var process = otherDomain.CreateInstanceAndUnwrap(
                 otherType.Assembly.FullName, otherType.FullName) as Process;

        Data d = new Data() { Info = "Hello" };
        process.SetData(d);
    }
}

public class Process : MarshalByRefObject
{

    public void SetData(Data data)
    {
        Data data1 = Data.Clone(data);
        Data data2 = data.Clone();

        Console.WriteLine(data1.Info); 
           // Debugger shows data1.Info as Hello

        Console.WriteLine(data2.Info); 
           // Outputs Hello, but Debugger shows data2 as     
           // System.Runtime.Remoting.Proxies.__TransparentProxy
    }

}

public class Data : MarshalByRefObject
{
    public string Info { get; set; }

    public Data Clone()
    {
        return Data.Clone(this);
    }

    public static Data Clone(Data old)
    {
        var clone = new Data();
        clone.Info = old.Info;
        return clone;
    }
}
  • 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-07T12:46:52+00:00Added an answer on June 7, 2026 at 12:46 pm

    When you call the static method from the other appdomain, the method is invoked in that appdomain and the new Data object is created in that appdomain. OTOH when you call the instance method, the call is marshaled to the object’s original appdomain, so the clone Data object is created in the original appdomain. Then it is marshaled back to the other appdomain as a transparent proxy and appears there as a retern value.

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

Sidebar

Related Questions

I have a section of code which should be executed by a maximum number
I have critical section in my application which contains a lot of code: which
We have a section of code which detects old URL's and performs a redirect
i have one section table which contain the section and i want to delete
Currently I have a section of code that needs to make about 7 web
I have a section of code that can be summarised as follows; void MyFunc()
I have the following section of code in an app that I am writing:
I have this view (DetailsContainer, first class in code section of this question) with
I have some VERY simple code to return the title for a section header:
In my xaml code, inside the Window.Resources section, I have defined a Data Template

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.