Page 1 of 1

Serialize Annotations to XML

Posted: Wed Jul 03, 2024 12:29 pm
by missionRoom
I'm trying to serialize a custom class that contains an AnnotationDataCollection using the below Serialize method. I keep getting an error regarding the AnnotationComment. Any way around this?

Serialize Method

Code: Select all

public static string SerializeToString(object obj)
{
    try
    {
        XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());

        using (StringWriter stringWriter = new StringWriter())
        {
            xmlSerializer.Serialize(stringWriter, obj);
            return stringWriter.ToString();
        }
    }
    catch (Exception ex)
    {
        log.Error("Error Serialising object to string", ex);
        return string.Empty;
    }
}
Error
There was an error reflecting type 'Vintasoft.Imaging.Annotation.Comments.AnnotationComment'.
To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. Vintasoft.Imaging.Annotation.Comments.CommentCollection does not implement Add(System.Object).

Re: Serialize Annotations to XML

Posted: Wed Jul 03, 2024 2:06 pm
by Alex
Hello,

Please send us (to support@vintasoft.com) a small console project, which allows to reproduce the problem. We need to reproduce the problem on our side.

Best regards, Alexander