I'm having a remoting issue in my application. Since the architecture is quite complex, I'll try to make an simple example with dummy names to illustrate the problem.
Consider these components:
- MyApp.Client.exe: client application
- MyApp.Service.exe: Windows service that hosts the server
- MyApp.Server.dll: server implementation
- MyApp.Shared.dll: shared library containing common interface and type definitions
In MyApp.Shared.dll, I have these interfaces:
public interface IFoo
{
...
}
public interface IFooManager
{
IList<IFoo> GetFooList();
...
}
Both interfaces are implemented in MyApp.Server.dll as MarshalByRefObjects
:
class Foo : MarshalByRefObject, IFoo
{
...
}
class FooManager : MarshalByRefObject, IFooManager
{
public IList<IFoo> GetFooList()
{
IList<IFoo> foos = new List<IFoo>();
// populate the list with instances of Foo
// ...
return foos;
}
...
}
On the client side, I have a proxy instance to the FooManager
object on the server. When I call GetFooList
on it, I can see that the FooManager.GetFooList()
method is executed, but when it returns I get the following SerializationException
:
Unable to find assembly 'MyApp.Server, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Server stack trace:
at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
at 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)
at System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create(String name, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMessage(Stream inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyApp.Shared.IFooManager.GetFooList()
...
at MyApp.Client.ViewModel.MainWindowViewModel.LoadFoos()
...
So I'm guessing it is trying to serialize the Foo
class (I don't get an exception when GetFooList
returns an empty list) or another type used in Foo
. But why would it try to serialize it ? Since Foo
is a MarshalByRefObject
, shouldn't it return a proxy to the Foo
instance ? And anyway, the IFoo
interface doesn't expose any object of types defined in MyApp.Server.dll...
The problem didn't appear before because all assemblies were in the same directory, so MyApp.Server.dll was probably loaded in the client AppDomain (which isn't supposed to happen). But now I'm trying to separate the client and server components, so the client shouldn't depend on a server-side assembly...
Does anyone have any idea about what is going on ? And how could I get more details about the exception (e.g. which type is it trying to serialize) ? The stack trace is not very helpful...