Object returned by proxy method must also be a proxy
Describe the bug When a proxy returns an object returned by its method, this object must also be a proxy. Classic remoting behaves like this
To Reproduce Steps to reproduce the behavior:
- For shared use this code or attached solution RemotingTestL.zip
namespace HelloWorld.Shared
{
public interface ISayHelloService
{
ISubTypeHelloService NewSubTypeHelloService(string name);
}
public interface ISubTypeHelloService
{
string GetName();
}
}
- use this code for implementation
public class SayHelloService : MarshalByRefObject, ISayHelloService
{
/// <inheritdoc />
public ISubTypeHelloService NewSubTypeHelloService(string name)
{
return new SubTypeHelloService(name);
}
}
[Serializable]
public class SubTypeHelloService : MarshalByRefObject, ISubTypeHelloService
{
private string _name;
public SubTypeHelloService(string name)
{
_name = name;
}
/// <inheritdoc />
public string GetName()
{
return _name;
}
}
- And this code for client
var client = new RemotingClient(new ClientConfig
{
ServerHostName = "localhost",
ServerPort = port,
Serializer = new BinarySerializerAdapter()
});
client.Connect();
// Create a proxy of the remote service, which behaves almost like a regular local object
var proxy = client.CreateProxy<ISayHelloService>();
var subtype = proxy.NewSubTypeHelloService("mySubType");
Debug.Assert(CoreRemoting.ClassicRemotingApi.RemotingServices.IsTransparentProxy(subtype));
var subtypeName = subtype.GetName();
- For Server use code from example
- Run Server and Client
- Exception System.Runtime.Serialization.SerializationException is thrown.
System.Runtime.Serialization.SerializationException: Не удалось найти сборку "HelloWorld.Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null". в System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() в System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name) в System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) в System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record) в System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum) в System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() в System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) в System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) в CoreRemoting.Serialization.Binary.BinaryFormatterExtensions.DeserializeSafe(BinaryFormatter formatter, Byte[] rawData) в CoreRemoting.Serialization.Binary.BinarySerializerAdapter.Deserialize[T](Byte[] rawData) в CoreRemoting.RemotingClient.ProcessRpcResultMessage(WireMessage message)
Expected behavior
The type of subtype must be Castle.Proxies.ISubTypeHelloServiceProxy
Additional notes
When I copy HelloWorld.Server.exe to client dir the type of subtype will be HelloWorld.Server.SubTypeHelloService. With classic Remoting proxy and subtype will be System.Runtime.Remoting.Proxies.__TransparentProxy both.