ActiveReports 14 Serialization

Posted by: jasonnguyen on 6 April 2020, 11:56 pm EST

  • Posted 6 April 2020, 11:56 pm EST

    I am converting from a previous version, and have not had an issue with serialization. Once I converted to AR14, it keeps failing on the serialization. Any help is appreciated. Here is a code snippet -

    public class SomeReport : SectionReport
    {
    //...
    }
    public void Test()
    {
    try
    {
    SomeReport report = new SomeReport();
    report.DataSource = new List<string>();
    report.Run();
    var ser = Serialize<SectionDocument>(report.Document);
    }
    catch (Exception ex)
    {
    var temp = ex;
    }
    }

    public static byte[] Serialize<T>(T data)
    {
    DataContractSerializer serializer = new DataContractSerializer(typeof(T));
    using (MemoryStream memoryStreamSource = new MemoryStream())
    {
    serializer.WriteObject(memoryStreamSource, data);
    using (MemoryStream memoryStreamDestination = new MemoryStream())
    {
    return memoryStreamDestination.ToArray();
    }
    }
    }
  • Replied 7 April 2020, 4:09 pm EST

    Hello,

    I tried to create a sample with the same code snippet but it is working at my end. Could you please modify the attached sample and send back to me so that I can reproduce the issue at my end.

    Thanks,
    Mohit
    Test_Serializer.zip
  • Replied 8 April 2020, 12:09 am EST

    Hi Mohit,

    When I run your solution, it fails on line 38 in the Form1.cs file. The try catch swallows the error. When you run it, are you not getting an exception on that line? Thanks for your help.

    Seems like we are missing the type and adding it does not seem to fix it - GrapeCity.ActiveReports.SerializableSectionDocument
  • Replied 7 April 2020, 11:31 pm EST



    Error message -
    Type 'GrapeCity.ActiveReports.SerializableSectionDocument' with data contract name 'SerializableSectionDocument:http://schemas.datacontract.org/2004/07/GrapeCity.ActiveReports' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.

    Stack -
    at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
    at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle originalDeclaredTypeHandle, Type graphType)
    at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
    at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
    at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
    at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
    at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(Stream stream, Object graph)
    at Test_Serializer.Form1.Serialize[T](T data) in C:\Users\jasonn\Downloads\file-36f74eb3-579a-4884-9144-94bb9c8ff7b6\Test_Serializer\Test_Serializer\Form1.cs:line 38
    at Test_Serializer.Form1..ctor() in C:\Users\jasonn\Downloads\file-36f74eb3-579a-4884-9144-94bb9c8ff7b6\Test_Serializer\Test_Serializer\Form1.cs:line 25
  • Replied 8 April 2020, 2:03 am EST

    Hello,

    I am really sorry for the confusion. I am able to replicate the issue at my end.
    Actually, MS permits to use ISerailzable in partial/medium trust: https://docs.microsoft.com/en-us/dotnet/standard/serialization/custom-serialization, so now SectionDocument doesn't implement this interface.

    If you still need to have serializable section document (to move it between application domains) - you should use simple derived class as follow:
    [Serializable]
    public class SerializableSectionDocument : SectionDocument, ISerializable
    {
    public SerializableSectionDocument()
    {
    }

    protected SerializableSectionDocument(SerializationInfo info, StreamingContext context) : base (info, context)
    {
    }
    }


    Hope it helps.

    Thanks,
    Mohit
  • Replied 8 April 2020, 2:19 am EST

    Hi Mohit,

    This is a breaking change for our very large code base. It is not a simple fix as you put it. Is there an escalation path for this issue? It will prevent us from moving to Active Reports 14.
  • Replied 8 April 2020, 2:33 am EST

    Hello Jason,

    I have forwarded your concern to our developer team(278944) and will inform you once I get any information from them.

    Thanks,
    Mohit
  • Marked as Answer

    Replied 16 April 2020, 5:05 pm EST

    Hello,

    As per dev, we use serializable document inside the report. You can directly use the 'Save' method of the Document. It should work faster. Or if you want to use serialize the document, then could you please try with other serializes. For example, BinarySerializer.

    Thanks,
    Mohit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels