title: Unable to make ShouldSerialize pattern work with XmlSerializer
body: <p>I have been able to use ShouldSerialize<em>Property</em> pattern with <code>XmlSerializer</code> to ignore a property of type <code>ICollection&lt;&gt;</code>. Below is the sample code. It works if I use <code>XmlIgnore</code> on <code>ListOfTestClassB</code> property but I want to achieve the same functionality utilizing <code>ShouldSerialize</code> pattern. If I run the code below I get the 'System.InvalidOperationException' saying:</p>
  
  <blockquote>
    <p>Cannot serialize member ConsoleApplication3.TestClassA.ListOfTestClassB of type System.Collections.Generic.ICollection`1[[ConsoleApplication3.TestClassB, ConsoleApplication3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.</p>
  </blockquote>
  
  <p>Can anyone highlight what am I missing?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Runtime.Serialization.Formatters.Binary;
  using System.Text;
  using System.Threading.Tasks;
  using System.Xml;
  using System.Xml.Serialization;
  
  namespace ConsoleApplication3
  {
     [Serializable]
     public class TestClassA
     {
        public int A { get; set; }
        public int B { get; set; }
        public string C { get; set; }
        public TestClassB TestClass { get; set; }
  
        public virtual ICollection&lt;TestClassB&gt; ListOfTestClassB { get; set; }
  
        public bool ShouldSerializeListOfTestClassB()
        {
           return false;
        }
     }
  
     [Serializable]
     public class TestClassB 
     {
        public int Int32 { get; set; }
        public string String { get; set; }
     }
  
  
     class Program
     {
        static object GetObject()
        {
           return new TestClassA { A = 1, B = 2, C = "test class a", TestClass = new TestClassB { Int32 = 11, String = "test class b"} };
        }
        static void Main(string[] args)
        {
           var result = new StringBuilder();
           var entity = GetObject();
           var ser = new XmlSerializer(entity.GetType());
  
           var settings = new XmlWriterSettings { OmitXmlDeclaration = true };
  
           using (var stream = new MemoryStream())
           {
              // make a copy of the entity - we do not want to serialize ZIP file !
              var formatter = new BinaryFormatter();
              formatter.Serialize(stream, entity);
              stream.Position = 0;
              entity = formatter.Deserialize(stream);
           }
  
           // serialize object
           ser.Serialize(XmlWriter.Create(result, settings), entity);
  
           Console.WriteLine(result.ToString());
           Console.ReadLine();
        }
     }
  }
  </code></pre>