Cannot serialize member… because it is an interface

前端 未结 2 823
误落风尘
误落风尘 2020-12-02 01:33

I have been having this problem and been pulling my hair out over it. I have the followin error:

Exception Details: System.NotSupportedException: Can

相关标签:
2条回答
  • 2020-12-02 02:02

    Not the source of your problem, but you need

    using (MemoryStream memoryStream = new MemoryStream())
    {
        serializer.Serialize(memoryStream, this);
        memoryStream.Seek(0, SeekOrigin.Begin);
        using (StreamReader reader = new StreamReader(memoryStream))
        {
            return reader.ReadToEnd();
        }
    }
    
    0 讨论(0)
  • 2020-12-02 02:21

    In the code you posted, the type of CustomerAddresses is IList<CustomerAdress>. That's an interface. Like the error message says, you can't serialize an interface.

    0 讨论(0)
提交回复
热议问题