I have an AppDomain, I CreateInstanceAndUnwrap on this AppDomain on an
object that inherits from MarshalByRefObject. The object that returns
is a __TransparentProxy, it is then cast to the interface the
underlying object implements. This object has an ArrayList property.
I'm able to read this ArrayList just fine, list[5] returns a value. But
all attempts to Add() items results in nothing happening. No exception
and the item is not added.
Does anyone know why this happens?
C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespaceWebQuestion
{
interfaceIListInterface
{
ArrayList Items { get; set; }
}
classListClass : MarshalByRefObject, IListInterface
{
private ArrayList items = new ArrayList{0,1,2,3,4,5};
public ArrayList Items
{
get
{
return items;
}
set
{
items = value;
}
}
}
classProgram
{
staticvoidMain(string[] args)
{
AppDomain ad = AppDomain.CreateDomain("OtherAppDomain");
IListInterface byRef = (IListInterface)ad.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "WebQuestion.ListClass");
foreach (object obj in byRef.Items)
{
Console.WriteLine(obj);
}
Console.WriteLine("Item Count before Add(): " + byRef.Items.Count); //Items.Count == 6
byRef.Items.Add("Item at index 6");
Console.WriteLine("Item Count after Add(): " + byRef.Items.Count); //Items.Count == 6, stilltry
{
Console.WriteLine("Getting item at Items[6]...");
Console.WriteLine(byRef.Items[6]); //throw exception
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
well my friend, the very idea of _TransparentProxy is that its a differant AppDomain, you cant access that appDomain, and change it directly but you can do a mixup
meaning, you will have an Abstract class that the DLL you load will inherit from and the loader will also inherit from, then you can execute commands directly to the DLL loaded via an abstract method
Stephen Bassoli3 reputationPosted Sep 30, 2009, 11:11 AM EDT
0
Thanks very much for the explanation. But do you know why I'm able to read from this Property of an object in another AppDomain but I'm not able to write?
Say the ArrayList Property was an int Property instead. I'm able to read and write the int Property just fine. Is this because the int is a value type and the ArrayList is a reference type? Does this read only behavior apply to all reference type Properties that are accessed directly?
Roei BarRank #1,271 · 1.4K reputationPosted Sep 29, 2009, 12:31 PM EDT
the very idea of _TransparentProxy is that its a differant AppDomain, you cant access that appDomain, and change it directly but you can do a mixup
meaning, you will have an Abstract class that the DLL you load will inherit from and the loader will also inherit from, then you can execute commands directly to the DLL loaded via an abstract method
Stephen Bassoli3 reputationPosted Sep 30, 2009, 11:11 AM EDT
Say the ArrayList Property was an int Property instead. I'm able to read and write the int Property just fine. Is this because the int is a value type and the ArrayList is a reference type? Does this read only behavior apply to all reference type Properties that are accessed directly?