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?
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace WebQuestion
{
interface IListInterface
{
ArrayList Items { get; set; }
}
class ListClass : MarshalByRefObject, IListInterface
{
private ArrayList items = new ArrayList{0,1,2,3,4,5};
public ArrayList Items
{
get
{
return items;
}
set
{
items = value;
}
}
}
class Program
{
static void Main(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, still
try
{
Console.WriteLine("Getting item at Items[6]...");
Console.WriteLine(byRef.Items[6]); //throw exception
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
|
Stephen BassoliPosted Sep 30, 2009, 3:11 PM
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 BarPosted Sep 29, 2009, 4:31 PM
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