title: XmlSerializer is throwing InvalidOperationException when using the generic type constraint where
body: <p>When I try to run the following code (two separated assemblies)</p>
  
  <h3>ClassLibrary.cs</h3>
  
  <pre><code>public interface ITest
  {
  }
  </code></pre>
  
  <h3>Program.cs</h3>
  
  <pre><code>using System;
  
  public class TestClass
  {
      public void Test&lt;T&gt;(T x) where T : ITest { }
  }
  
  static class Program
  { 
      static void Main(string[] args)         
      {
          new System.Xml.Serialization.XmlSerializer(typeof(TestClass));
      }
  }
  </code></pre>
  
  <p>Compiled in Windows 7 64-Bit using the following commands:</p>
  
  <blockquote>
    <p>c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc /target:library ClassLibrary.cs</p>
    
    <p>c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc /reference:ClassLibrary.dll Program.cs</p>
  </blockquote>
  
  <p>I'm getting the this exception:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: Unable to generate a temporary class
    (result=1). error CS0012: The type
    ITest is defined in an assembly that
    is not referenced. You must add a
    reference to assembly ClassLibrary,
    Version=0.0.0.0, Culture=neutral,
    PublicKeyToken=null hinzu.</p>
    
    <p>at
    System.Xml.Serialization.Compiler.Compile(Assembly
    parent, String ns,
    XmlSerializerCompilerParameters
    xmlParameters, Evidence evidence)<br>
    at
    System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[]
    xmlMappings, Type[] types, String
    defaultNamespace, Evidence evidence,
    XmlSerializerCompilerParameters
    parameters, Assembly assembly,
    Hashtable assemblies)    at
    System.Xml.Serialization.TempAssembly..ctor(XmlMapping[]
    xmlMappings, Type[] types, String
    defaultNamespace, String location,
    Evidence evidence)    at
    System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping
    xmlMapping, Type type, String
    defaultNamespace)    at
    System.Xml.Serialization.XmlSerializer..ctor(Type
    type, String defaultNamespace)    at
    Program.Main(String[] args)</p>
  </blockquote>
  
  <p>Removing the <em>where T : ITest</em> from <em>TestClass</em> or not using generics at all (e.g. using <em>public void Test(ITest x)</em>) will prevent the exception from being thrown but I need this construct in my real application.</p>
  
  <p>Do anybody understand why the XmlSerializer is unable to handle the where constraint?</p>