The problem is that List<T>
is not in itself a MarshalByRefObject
, rather, it is a serializable class. When you call the Add()
method on your list, what you're actually doing is asking the remote object to serialise its list, deserialise it locally and then call the method on the local object. Your changes will never be propagated back to the remote instance of the list object.
You will have to provide methods in your IpcInterface
class to manipulate the list; because this type inherits from MarshalByRefObject
, the methods will be called on the remote object instead of a locally-deserialised instance.
i.e.
public class IpcInterface : MarshalByRefObject {
public List<String> strings;
public void Add(string value) {
strings.Add(value);
}
}
You may also want to expose strings
as a read-only collection, otherwise you're giving the impression that it can be manipulated directly (which it cannot).