Using XmlSerializer from .Net 4, I am trying to serialize a class that contains two classes with the same name, but different namespace.
[XmlInclude(typeof(MyNamespace1.MyClass))]
[XmlInclude(typeof(MyNamespace2.MyClass))]
public class SuperInfo
{
public MyNamespace1.MyClass A{ get; set; }
public MyNamespace2.MyClass B{ get; set; }
}
It turned out that the serializer could not distinguish between these 2 classes I had with the same name. The exception shows:
'Types MyNamespace1.MyClass' and 'MyNamespace2.MyClass' both use the XML type name, 'MyClass', from namespace ''. Use XML attributes to specify a unique XML name and/or namespace for the type.
I found a solution in this thread, consisting in decorate the homonymous classes with attributes like this:
[XmlType("BaseNamespace1.MyClass")]
[XmlType("BaseNamespace2.MyClass")]
but I'm not allowed to do that, because in my case, those classes come from an automatic generated proxy to a web service.
Do you have a solution?