title: How to avoid SerializationException: Type is not resolved for member XXX when testing a component that uses the LogicalCallContext
body: <p>I've recently started hitting the following exception in my unit test (NUnit) code when EF tries to load information from App.config:</p>
  
  <pre><code>System.Runtime.Serialization.SerializationException : Type is not resolved for member [my type name], [my assembly name]
  </code></pre>
  
  <p>This happens both with the NUnit GUI runner and with R#'s VS-integrated runner. Here's a quick unit test that reproduces the issue:</p>
  
  <pre><code>[Test]
  public void Test()
  {
      // adding 
      // ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
      // here fixes things, probably because the configuration is cached
  
      CallContext.LogicalSetData("FooSlot", new Foo()); // removing this line fixes things
      ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // fails with above exception
  }
  
  [Serializable] // removing this gives a different exception complaining that Foo is not Serializable
  public class Foo // : MarshalByRefObject // this fixes things
  { 
  }
  </code></pre>
  
  <p>Using the fusion log viewer, I found that the failure was a result of a </p>
  
  <blockquote>
    <p>FILE_NOT_FOUND HRESULT</p>
  </blockquote>
  
  <p>error. Basically, it seems like opening the configuration somehow causes the Foo object to be sent
  back to the original (nunit runner) app domain, which then tries to load my assembly and can't find it because it's not in the bin folder. In fact, I confirmed that copying my assembly to the NUnit runner bin folder is another way to fix the issue.</p>
  
  <p>At this point, it seems like using <code>MarshalByRefObject</code> is the best option. However, I'd love to here if there are better options and/or if someone can offer a thorough explanation of exactly what is going on and why. Are there any disadvantages to using <code>MarshalByRefObject</code> here?</p>
  
  <p>This is different than <a href="https://stackoverflow.com/questions/13729089/serializationexception-type-is-not-resolved-for-member">this question</a>, because I have already identified <code>MarshalByRefObject</code> as a potential solution and am trying to understand the problem in more depth / understand the implications of <code>MarshalByRefObject</code>. The answer to that post is just a callout to <code>MarshalByRefObject</code> with no useful additional detail.</p>