Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing XPS files fails on Windows 8.1 #2106

Open
pieterphilippaerts opened this issue Oct 24, 2019 · 4 comments
Open

Printing XPS files fails on Windows 8.1 #2106

pieterphilippaerts opened this issue Oct 24, 2019 · 4 comments
Assignees
Labels
Bug Product bug (most likely) regression status: This issue is a regression from a previous build or release
Milestone

Comments

@pieterphilippaerts
Copy link

Hi everyone,

I'm using .NET Core 3 to print XPS files. The code I have is simple and working perfectly on Windows 7 and Windows 10, but it fails on Windows 8.1 (multiple machines, both 32-bit and 64-bit).

I've tried a number of different variations of the printing code, but here's a simple example:

var pd = new PrintDialog();
if (pd.ShowDialog() == true) {
    var tdoc = new XpsDocument(@"<SOMEPATH>\temp.xps", FileAccess.ReadWrite);
    pd.PrintDocument(tdoc.GetFixedDocumentSequence().DocumentPaginator, "temp.xps");
}

This code works perfectly on Windows 7 and Windows 10, but on Window 8.1 I always get the following exception:

System.IO.IOException: Cannot retrieve parts of writeonly container
at System.IO.Packaging.Package.ThrowIfWriteOnly()
at System.IO.Packaging.Package.GetRelationshipsByType(String relationshipType)
at System.Windows.Xps.Packaging.XpsManager.GetXpsDocumentStartingPart(Package package)
at System.Windows.Xps.Packaging.XpsDocument.AddFixedDocumentSequence()
at System.Windows.Xps.Serialization.XpsPackagingPolicy.AcquireXmlWriterForFixedDocumentSequence()
at System.Windows.Xps.Serialization.XpsSerializationManager.AcquireXmlWriter(Type writerType)
at System.Windows.Xps.Serialization.DocumentSequenceSerializer.get_XmlWriter()
at System.Windows.Xps.Serialization.DocumentSequenceSerializer.PersistObjectData(SerializableObjectContext serializableObjectContext)
at System.Windows.Xps.Serialization.ReachSerializer.SerializeObject(Object serializedObject)
at System.Windows.Xps.Serialization.XpsSerializationManager.SaveAsXaml(Object serializedObject)
at System.Windows.Xps.XpsDocumentWriter.SaveAsXaml(Object serializedObject, Boolean isSync)
at System.Windows.Xps.XpsDocumentWriter.Write(DocumentPaginator documentPaginator, PrintTicket printTicket)
at System.Windows.Controls.PrintDialog.PrintDocument(DocumentPaginator documentPaginator, String description)

I don't see any problems with the code, and the exact same code is actually working on Windows 8.1 if I use it in the full .NET Framework!! So this looks like a bug in .NET Core 3 (specifically on Windows 8.1).

Also note that I've really tried many variations of the printing code (including PrintDialog.PrintVisual, PrintQueue.AddJob, XpsDocumentWriter.Write, XpsDocumentWriter.WriteAsync, creating the XpsDocument in memory instead of from a file, ...), but none of them worked on Windows 8.1 and I always get similar exceptions, for example:

System.IO.IOException: Cannot retrieve parts of writeonly container
at System.IO.Packaging.Package.ThrowIfWriteOnly()
at System.IO.Packaging.Package.GetRelationshipsByType(String relationshipType)
at System.Windows.Xps.Packaging.XpsManager.GetXpsDocumentStartingPart(Package package)
at System.Windows.Xps.Packaging.XpsDocument.AddFixedDocumentSequence()
at System.Windows.Xps.Serialization.XpsPackagingPolicy.AcquireXmlWriterForFixedDocumentSequence()
at System.Windows.Xps.Serialization.XpsSerializationManager.AcquireXmlWriter(Type writerType)
at System.Windows.Xps.Serialization.ReachHierarchySimulator.SimulateBeginFixedDocumentSequence()
at System.Windows.Xps.Serialization.ReachHierarchySimulator.BeginConfirmToXPSStructure(Boolean mode)
at System.Windows.Xps.Serialization.XpsSerializationManager.SaveAsXaml(Object serializedObject)
at System.Windows.Xps.XpsDocumentWriter.SaveAsXaml(Object serializedObject, Boolean isSync)
at System.Windows.Xps.XpsDocumentWriter.Write(Visual visual, PrintTicket printTicket)
at System.Windows.Controls.PrintDialog.PrintVisual(Visual visual, String description)

This issue seems to be related to issue 597 (#597). this appears to be the exact same problem, however issue 597 was closed and marked as fixed.
If I execute the exact same code as the author of issue 597 (i.e. "PrintQueue.CreateXpsDocumentWriter(LocalPrintServer.GetDefaultPrintQueue()).Write(visual);"), I get the exact exception he got:

System.IO.IOException: Cannot retrieve parts of writeonly container
at System.IO.Packaging.Package.ThrowIfWriteOnly()
at System.IO.Packaging.Package.GetRelationshipsByType(String relationshipType)
at System.Windows.Xps.Packaging.XpsManager.GetXpsDocumentStartingPart(Package package)
at System.Windows.Xps.Packaging.XpsDocument.AddFixedDocumentSequence()
at System.Windows.Xps.Serialization.XpsPackagingPolicy.AcquireXmlWriterForFixedDocumentSequence()
at System.Windows.Xps.Serialization.XpsSerializationManager.AcquireXmlWriter(Type writerType)
at System.Windows.Xps.Serialization.ReachHierarchySimulator.SimulateBeginFixedDocumentSequence()
at System.Windows.Xps.Serialization.ReachHierarchySimulator.BeginConfirmToXPSStructure(Boolean mode)
at System.Windows.Xps.Serialization.XpsSerializationManager.SaveAsXaml(Object serializedObject)
at System.Windows.Xps.XpsDocumentWriter.SaveAsXaml(Object serializedObject, Boolean isSync)
at System.Windows.Xps.XpsDocumentWriter.Write(Visual visual)

Is it possible that the fix for issue 597 isn't working on Windows 8.1 for some reason?

@grubioe grubioe added the Bug Product bug (most likely) label Oct 24, 2019
@grubioe grubioe modified the milestones: 3.1, 5.0 Oct 24, 2019
@grubioe grubioe added the regression status: This issue is a regression from a previous build or release label Oct 24, 2019
@arpitmathur arpitmathur modified the milestones: 3.1, 5.0 Nov 7, 2019
@rladuca rladuca removed their assignment Apr 24, 2020
@sandeep200321
Copy link

hi I am also facing a print issue in windows 8.1. Could you please confirm if this is related issue ? Link is below. If so can it be delivered early in .net version 3.1 ?

https://developercommunity.visualstudio.com/content/problem/1017810/print-issue-in-wpf-net-core-30-screen-hangs.html

@wstaelens
Copy link
Contributor

#1363

is this already fixed? (server2012r2)

@ryalanms ryalanms modified the milestones: 5.0.0, 7.0.0 Aug 26, 2021
@ryalanms
Copy link
Member

This needs to be backported to 3.1 from 6.0.

@ryalanms ryalanms self-assigned this Aug 26, 2021
@wstaelens
Copy link
Contributor

2 years later ha! 7.0.0 milestone 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Product bug (most likely) regression status: This issue is a regression from a previous build or release
Projects
None yet
Development

No branches or pull requests

7 participants