title: Strange .NET remoting SerializationException with MarshalByRefObject
body: <p>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.</p>
  
  <p>Consider these components:</p>
  
  <ul>
  <li>MyApp.Client.exe: client application</li>
  <li>MyApp.Service.exe: Windows service that hosts the server</li>
  <li>MyApp.Server.dll: server implementation</li>
  <li>MyApp.Shared.dll: shared library containing common interface and type definitions</li>
  </ul>
  
  <p>In MyApp.Shared.dll, I have these interfaces:</p>
  
  <pre><code>public interface IFoo
  {
      ...
  }
  
  public interface IFooManager
  {
      IList&lt;IFoo&gt; GetFooList();
      ...
  }
  </code></pre>
  
  <p>Both interfaces are implemented in MyApp.Server.dll as <code>MarshalByRefObjects</code>:</p>
  
  <pre><code>class Foo : MarshalByRefObject, IFoo
  {
      ...
  }
  
  class FooManager : MarshalByRefObject, IFooManager
  {
      public IList&lt;IFoo&gt; GetFooList()
      {
          IList&lt;IFoo&gt; foos = new List&lt;IFoo&gt;();
          // populate the list with instances of Foo
          // ...
          return foos;
      }
  
      ...
  }
  </code></pre>
  
  <p>On the client side, I have a proxy instance to the <code>FooManager</code> object on the server. When I call <code>GetFooList</code> on it, I can see that the <code>FooManager.GetFooList()</code> method is executed, but when it returns I get the following <code>SerializationException</code>:</p>
  
  <pre><code>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&amp; msgData, Int32 type)
     at MyApp.Shared.IFooManager.GetFooList()
     ...
     at MyApp.Client.ViewModel.MainWindowViewModel.LoadFoos()
     ...
  </code></pre>
  
  <p>So I'm guessing it is trying to serialize the <code>Foo</code> class (I don't get an exception when <code>GetFooList</code> returns an empty list) or another type used in <code>Foo</code>. But why would it try to serialize it ? Since <code>Foo</code> is a <code>MarshalByRefObject</code>, shouldn't it return a proxy to the <code>Foo</code> instance ? And anyway, the <code>IFoo</code> interface doesn't expose any object of types defined in MyApp.Server.dll...</p>
  
  <p>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...</p>
  
  <p>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...</p>