Serialize Annotations to XML

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

missionRoom
Posts: 19
Joined: Wed Jan 22, 2020 4:38 pm

Serialize Annotations to XML

Post 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).
Alex
Site Admin
Posts: 2397
Joined: Thu Jul 10, 2008 2:21 pm

Re: Serialize Annotations to XML

Post 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