Skip to content

Commit a57ed01

Browse files
rladucaRobert LaDuca
authored and
Robert LaDuca
committed
In .NET Core 3.0 System.IO.Compression's ZipArchive does not support multiple ZipArchiveEntries to be open concurrently when using FileAccess.Write. This is a requirement of the XPS serialization stack in WPF. As such, we need to create XPS documents as FileAccess.ReadWrite in order to allow this behavior.
1 parent 024e025 commit a57ed01

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -894,9 +894,13 @@ bool testIsSignable
894894
Stream dataStream
895895
)
896896
{
897+
// In .NET Core 3.0 System.IO.Compression's ZipArchive does not allow creation of ZipArchiveEntries when
898+
// a prior ZipArchiveEntry is still open. XPS Serialization requires this as part of its implementation.
899+
// To get around this, XPS creation should occur in with FileAccess.ReadWrite if the underlying stream
900+
// supports it. This allows multiple ZipArchiveEntries to be open concurrently.
897901
Package package = Package.Open(dataStream,
898902
FileMode.CreateNew,
899-
FileAccess.Write);
903+
(dataStream.CanRead) ? FileAccess.ReadWrite : FileAccess.Write);
900904
XpsDocument document = new XpsDocument(package);
901905

902906
document.OpcPackage = package;

src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,13 @@ CompressionOption compressionOption
139139
{
140140
if( packageAccess == FileAccess.Write )
141141
{
142+
// In .NET Core 3.0 System.IO.Compression's ZipArchive does not allow creation of ZipArchiveEntries when
143+
// a prior ZipArchiveEntry is still open. XPS Serialization requires this as part of its implementation.
144+
// To get around this, XPS creation should occur in with FileAccess.ReadWrite. This allows multiple
145+
// ZipArchiveEntries to be open concurrently.
142146
package = Package.Open(path,
143147
FileMode.Create,
144-
packageAccess,
148+
FileAccess.ReadWrite,
145149
FileShare.None);
146150
streaming = true;
147151
}

0 commit comments

Comments
 (0)