wpf: XpsDocument.GetFixedDocumentSequence throws NotSupportedException

• NET Core Version: 3.0.0-preview6-27804-01 (also in preview 5). • Windows version: Win10 • Does the bug reproduce also in WPF for .NET Framework 4.8?: No

An attempt is made to read an XPS document from disk:

var doc = new XpsDocument("path to file", FileAccess.Read);
var seq = doc.GetFixedDocumentSequence();

The following exception is thrown:

System.Windows.Markup.XamlParseException: ''Initialization of 'System.Windows.Documents.FixedDocument' threw an exception.' Line number '1' and line position '479'.'

Inner exception:

NotSupportedException: Specified method is not supported.

Stack trace:

at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, Boolean skipJournaledProperties, Uri baseUri)
   at System.Windows.Markup.XamlReader.Load(XamlReader xamlReader, ParserContext parserContext)
   at System.Windows.Markup.XamlReader.Load(XmlReader reader, ParserContext parserContext, XamlParseMode parseMode, Boolean useRestrictiveXamlReader)
   at System.Windows.Markup.XamlReader.Load(Stream stream, ParserContext parserContext, Boolean useRestrictiveXamlReader)
   at System.Windows.Markup.XamlReader.Load(Stream stream, ParserContext parserContext)
   at System.Windows.Xps.Packaging.XpsDocument.GetFixedDocumentSequence()

This appears to be a different issue to #575.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (12 by maintainers)

Most upvoted comments

@elyoh @weltkante This actually turned out to be the same error, just caught in a slightly different manner.

When running with my recent fixes for #585, the document displays correctly.

image

When running without those changes, I get the same error on accessing DeflateStream.Position. The difference here is the call stack that leads to the error has an error trap that re-throws.

EDIT: Re-throws isn’t the right term, converts the exception to an HR, which then looks like some native call failed on the way back up.

See here.

In any case, the same workaround will help with your issue as I gave in #585 , open the XPS as read/write.

Fixed by #1311

@elyoh Thanks! I’ll have a look today and see what I can figure out.

Here is a sample xps file which leads to the error.

2069bGRVwEKTGite3tlNJw.zip

I tried using the same file in 3.0.100-preview8-013330 and received the same error.

@rladuca these stack traces here from @elyoh and in #585 from @jbartlau look different. One stack trace is a managed NotSupportedException from DeflateStream.get_Position() but the other is a HRESULT native exception from TextInterface.Factory.CreateFontFace. I’m not sure they have the same root cause, the stack traces sure don’t look that way.

@rladuca The xps file does reference fonts on the local system. It is a print out of an on screen view written in xaml. I’ll get a sample xps file uploaded on Friday.

The workaround here will be fairly straightforward and should follow what I did here: https://github.com/dotnet/wpf/pull/995/files#diff-7b801941d4352acdc7ea9eeaba96fecd

Inner exception stack trace:

at MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32 hr)
   at MS.Internal.Text.TextInterface.Factory.CreateFontFace(Uri filePathUri, UInt32 faceIndex, FontSimulations fontSimulationFlags)
   at System.Windows.Media.GlyphTypeface.Initialize(Uri typefaceSource, StyleSimulations styleSimulations)
   at System.Windows.Media.GlyphTypeface..ctor(Uri typefaceSource, StyleSimulations styleSimulations)
   at System.Windows.Documents.Glyphs.ParseGlyphRunProperties()
   at System.Windows.Documents.Glyphs.ComputeMeasurementGlyphRunAndOrigin()
   at System.Windows.Documents.Glyphs.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Canvas.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Canvas.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Canvas.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Canvas.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Canvas.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Canvas.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Documents.FixedPage.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Documents.FixedDocument.GetPage(Int32 pageNumber)
   at System.Windows.Documents.FixedDocument.OnInitialized(Object sender, EventArgs e)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)