Last Updated: 03 Nov 2023 06:47 by ADMIN
Release R3 2023 SP1
Created on: 24 Oct 2023 04:24
Category: ZipLibrary
Type: Bug Report
System.NotSupportedException When trying to serialize class into a ArchiveEntry stream

I'm trying to implement the IXmlSerialization for class SerializableDictionary. When starts the serialization of class to xml, I'm catching the System.NotSupportedException: 'Can't flush final block twice'. The problem occurs when second serializer trying to call Serialize method on same XmlWriter. 

using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, false, null))
        foreach (var item in array)
            using (var entry = archive.CreateEntry($"{item.Name}.reg-ext"))
                XmlInOut<RegulationItem>.SaveToStream(entry.Open(), item);

Could it be bug with the ArchiveEntry Stream?

I've placed a solution into a github repo. Also I tried to replace the stream of entry with the MemoryStream, and it helps. But I would to do it directly, if it's possible. 

The original question.

1 comment
Posted on: 26 Oct 2023 11:40

Hello, Kostiantyn. 

Thank you for sharing this and for the project helping us to reproduce the issue. I was able to run and reproduce it. Looking into our source code it seems that the stream is flushed twice. We do have verification for this however calling it from an external source seems to break it. I forwarded this to our developers for looking into this. I converted this thread to a bug report. You can subscribe to it and track the progress of this item.