Actually, you can be VERY close and not even know this.
Try defining an empty helper class inside your ClassLibrary assembly and place [Serializable, XmlInclude(SerializationReferenceHelper)] just above the public class TestClass .
The problem is that the Xml parser is not aware of the second class, because it is in a different assembly and only refers to the where clause in your code. Yes, Microsoft could write a little tune for viewing in all known assemblies ... I donβt know why they do not. But for now, this might work.
Classlibrary
public class SerializationReferenceHelper { } public interface ITest { }
Program
[Serializable, XmlInclude(typeof(SerializationReferenceHelper))] public class TestClass { public void Test<T>(T x) where T : ITest { } } static class Program { static void Main(string[] args) { new System.Xml.Serialization.XmlSerializer(typeof(TestClass)); } }
Jerry
source share