// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Xml.Serialization; namespace E { public class Investment { } public class Stock : Investment { } public class Program { public static void Main(string[] args) { List lst = new List(); lst.Add(new Stock()); lst.Add(new Stock()); try { XmlSerializer ser = new XmlSerializer(typeof(List)); ser.Serialize(Console.Out, lst); } catch(InvalidOperationException) { Console.WriteLine("Expected exception"); } XmlSerializer ser2 = new XmlSerializer(typeof(List), new Type[] { typeof(Stock) }); ser2.Serialize(Console.Out, lst); } } }