title: XmlSerializer can't find EntityObject even though its referenced
body: <p>I hope that someone can help me with this problem that I've been having with XmlSerializer. </p>
  
  <p>I've already looked through this thread: <a href="http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/551cee76-fd80-48f8-ac6b-5c22c234fecf/" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/551cee76-fd80-48f8-ac6b-5c22c234fecf/</a></p>
  
  <p>The error I am getting is:</p>
  
  <p>System.InvalidOperationException: Unable to generate a temporary class (result=1).
  error CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.</p>
  
  <p>I've made sure that my unit test has a reference to System.Data.Entity, so it is able to compile at least.  I've also in the app.config made an assembly binding to System.Data.Entity.</p>
  
  <p>Here's my rough class structure</p>
  
  <pre><code>[Serializable] 
  [XmlRoot(Namespace = XmlSupport.MyNamespace, ElementName = XmlSupport.WantToSerialize)] 
  [XmlInclude(typeof(WantToSerializeBaseClass)]
  [XmlInclude(typeof(EntityObject)]
  [XmlInclude(typeof(MyEntityObjectSubClass)]
  public class WantToSerialize : WantToSerializeBaseClass, IXmlSerializable  (I've tried putting this on the baseclass and the current class)
  {
    // methods and classes 
    // I've included XmlIncludes for all the classes that this class has a reference too
    //  even though in the WriteXml it just uses .NET base classes
  }
  </code></pre>
  
  <p>The WantToSerializeBaseClass makes use of some generics, but I've decorated it with XmlIncludes for (EntityObject, and any other classes it makes reference to as well).</p>
  
  <p>the calling code:</p>
  
  <pre><code>var serializerWrite = new XmlSerializer(typeof (WantToSerialize), XmlSupport.ITNNamespace); 
  </code></pre>
  
  <p>fails</p>
  
  <p>However if I do:</p>
  
  <pre><code>var serializerWrite = new XmlSerializer(typeof (WantToSerialize), new Type[] {typeof(EntityObject)}); 
  </code></pre>
  
  <p>it is succesfull.</p>
  
  <p>Any thoughts would be most helpful.</p>
  
  <p><strong>UPDATED</strong>
  I've tracked the problem down to a method in the WantToSerializeBaseClass</p>
  
  <pre><code>public abstract void ConvertFromEntity&lt;TtoCopy&gt;(TtoCopy toCopy) where TtoCopy : MyEntityObjectSubClass;
  </code></pre>
  
  <p>Where MyEntityObjectSubClass is a subclass of EntityObject, that adds a few methods that I want on my entity objects.  The MyEntityObjectSubClass looks like this:</p>
  
  <pre><code>[Serializable]
  [XmlInclude(typeof(EntityObject))]
  public abstract class MyEntityObjectSubClass : EntityObject, IMyEntityObjectSubClass 
  </code></pre>
  
  <p>Again any thoughts would be great</p>