Skip to content

Commit c7dcf50

Browse files
authored
Merge pull request #2081 from rladuca/xpsmanfix
[Release/3.1] Change XPS document creation to use FileAccess.ReadWrite instead of FileAccess.Write
2 parents cde0da6 + 343d67a commit c7dcf50

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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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)