The title says it all, consider this program:
using System;
using System.Xml.Serialization;
public interface ITest
{
public sealed class Test //: ITest
{
public string TestString { get; set; }
}
string TestString { get; }
}
public sealed class Test : ITest
{
public string TestString { get; set; }
}
public class Program
{
public static void Main()
{
var serializer1 = new XmlSerializer(typeof(Test));
Console.WriteLine($"{nameof(serializer1)} created.");
var serializer2 = new XmlSerializer(typeof(ITest.Test));
Console.WriteLine($"{nameof(serializer2)} created.");
}
}
The output is:
serializer1 created. Unhandled exception. System.NotSupportedException: Cannot serialize interface ITest. at System.Xml.Serialization.TypeDesc.CheckSupported() at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError) at System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference) at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError) at System.Xml.Serialization.ModelScope.GetTypeModel(Type type, Boolean directReference) at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace) at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace) at System.Xml.Serialization.XmlSerializer..ctor(Type type)
But ITest.Test
is not an interface, it is a (concrete) sealed class!!
What's going on? is it a bug maybe?