0

I am trying to Serialise the class 'Person', which contains a property where the type is an interface.

I a getting an exception - System.NotSupportedException - saying ----> System.NotSupportedException : Cannot serialize member Tests.Person.Names of type Writer.Tests.INames because it is an interface.

Is there a way round this? Or just simply can not be done.

 public interface INames
    {
        string First { get; set; }
        string Last { get; set; }
    }

    public class Names : INames
    {
        public string First { get; set; }
        public string Last { get; set; }
    }

    public class Person
    {
        public INames Names { get; set; }
        public double WeightKg { get; set; }
        public double HeightCm { get; set; }
    }
user98
  • 17
  • 5
  • supporting [link](https://stackoverflow.com/questions/31630614/cannot-serialize-member-x-because-it-is-an-interface) – Kanhaya Tyagi Dec 06 '22 at 13:00
  • Does this answer your question? [XML serialization of interface property](https://stackoverflow.com/questions/1333864/xml-serialization-of-interface-property) – Mykhailo Svyrydovych Dec 06 '22 at 13:14

0 Answers0