XmlRoot gets overwritten when using System.Xml.Serialization Serializing Generic class

82 views Asked by At

Dear StackOverflow lovers,

I'm having my XmlRoot overwritten whenever I try to serialize a object from a generic class.

=> I get as XmlRoot: classname + _x0060_1 (by the way, there is a 1 because there is only one Type parameters given, in other word it could be any number of type parameter needed)

Even if I use

[XmlRoot("BaseSyncOneWayInput")]

or even

XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = typeof(T).Name;

Here is a .NET Fiddle to reproduce to bug: https://dotnetfiddle.net/X9fRkA

1

There are 1 answers

4
jdweng On

I don't see the issue. I added a test class to your code and modified you main() method to use class. Results work.

        static void Main(string[] args)
        {
            MyListClass[] myListClass = new MyListClass[3];
            Console.WriteLine(Pull<string>("","",myListClass));
        }
    }
    public class MyListClass
    {
        string myProperty { get; set; }
    }