You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BugProduct bug (most likely)rank20Rank: Priority/rank on a scale of (1..100)regressionstatus: This issue is a regression from a previous build or release
• 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()
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)
@elyoh This seems like something specific to the XPS being displayed or something that has been fixed in Preview8.
I tested this against several XPS documents sitting around in our test code and I was able to display them all without an error on 3.0.100-preview8-013275.
Can you test against the latest daily build and, if this still reproduces, supply an XPS document that causes the issue to occur?
#585 (comment) seems to actually have a similar stack in Preview 8. Using the document from that repro, I get:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
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.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 System.Windows.FrameworkContentElement.RaiseInitialized(EventPrivateKey key, EventArgs e)
at System.Windows.FrameworkContentElement.OnInitialized(EventArgs e)
at System.Windows.FrameworkContentElement.TryFireInitialized()
at System.Windows.FrameworkContentElement.EndInit()
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
This looks like our initialization of TypeFaces is directly calling into an unsupported part of the new zip implementation.
Take a look at this stack:
System.IO.Compression.dll!System.IO.Compression.DeflateStream.Position.get() Line 167 C#
System.IO.Packaging.dll!System.IO.Packaging.ZipWrappingStream.Position.get() Line 95 C#
> PresentationCore.dll!MS.Internal.IO.Packaging.SynchronizingStream.Position.get() Unknown
PresentationCore.dll!MS.Internal.IO.Packaging.DeobfuscatingStream.Read(byte[] buffer, int offset, int count) Unknown
PresentationCore.dll!MS.Internal.FontCache.FontSource.StreamToByteArray(System.IO.Stream fontStream) Unknown
PresentationCore.dll!MS.Internal.FontCache.FontSource.GetUnmanagedStream() Unknown
DirectWriteForwarder.dll!MS.Internal.Text.TextInterface.FontFileStream.FontFileStream(MS.Internal.Text.TextInterface.IFontSource fontSource) Unknown
DirectWriteForwarder.dll!MS.Internal.Text.TextInterface.FontFileLoader.CreateStreamFromKey(void* fontFileReferenceKey, uint fontFileReferenceKeySize, System.IntPtr* fontFileStream) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
DirectWriteForwarder.dll!MS.Internal.Text.TextInterface.Factory.GetFontCollection(System.Uri uri) Unknown
PresentationCore.dll!MS.Internal.FontCache.DWriteFactory.GetFontCollectionFromFileOrFolder(System.Uri fontCollectionUri, bool isFolder) Unknown
PresentationCore.dll!MS.Internal.FontCache.DWriteFactory.GetFontCollectionFromFile(System.Uri fontCollectionUri) Unknown
PresentationCore.dll!System.Windows.Media.GlyphTypeface.Initialize(System.Uri typefaceSource, System.Windows.Media.StyleSimulations styleSimulations) Unknown
I have a feeling this is going to affect any XPS with local font resources. That's a pretty basic feature of XPS documents that won't work if we don't figure out some way around this.
Interestingly enough, we have a test XPS document that has embedded fonts, but the entire archive is a flat structure (the fonts are located in the root of the archive). This file displays with no issue.
I have to examine what code paths are taken in that instance.
@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.
@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.
@weltkante The second stack I posted is the actual exception stack from loading @jbartlau's file with first chance exceptions turned on. Loading the font when the font is located within the XPS always tries to access position, assuming it doesn't live in the root of the archive. Take a look at the offending code in DeobfuscatingStream and you'll see what I am talking about.
I'm pretty sure the root cause of both issues is exactly the same even if the various stacks are slightly different in how we get there.
@weltkante Ah, I see where I might have conflated the two. I assumed the font loading path would get hit both ways. I'll wait for @elyoh's reproduction XPS first.
@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.
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.
BugProduct bug (most likely)rank20Rank: Priority/rank on a scale of (1..100)regressionstatus: This issue is a regression from a previous build or release
Activity
[-]XpsDocument.GetFixedDocumentSequence[/-][+]XpsDocument.GetFixedDocumentSequence throws NotSupportedException[/+]weltkante commentedon Jun 24, 2019
elyoh commentedon Jun 24, 2019
Inner exception stack trace:
weltkante commentedon Jun 25, 2019
That looks different from what I'd expect for #585 so probably needs a separate investigation.
rladuca commentedon Jul 16, 2019
@elyoh This seems like something specific to the XPS being displayed or something that has been fixed in Preview8.
I tested this against several XPS documents sitting around in our test code and I was able to display them all without an error on
3.0.100-preview8-013275.Can you test against the latest daily build and, if this still reproduces, supply an XPS document that causes the issue to occur?
rladuca commentedon Jul 16, 2019
#585 (comment) seems to actually have a similar stack in Preview 8. Using the document from that repro, I get:
@stevenbrix @vatsan-madhavan We should sync up on what we know from #585.
CC: @jbartlau since I used your reproduction document to mirror the same failure here.
rladuca commentedon Jul 16, 2019
This looks like our initialization of TypeFaces is directly calling into an unsupported part of the new zip implementation.
Take a look at this stack:
I have a feeling this is going to affect any XPS with local font resources. That's a pretty basic feature of XPS documents that won't work if we don't figure out some way around this.
@elyoh does your XPS document contain fonts?
rladuca commentedon Jul 16, 2019
DeflateStream has this code:
rladuca commentedon Jul 16, 2019
Interestingly enough, we have a test XPS document that has embedded fonts, but the entire archive is a flat structure (the fonts are located in the root of the archive). This file displays with no issue.
I have to examine what code paths are taken in that instance.
stevenbrix commentedon Jul 16, 2019
The workaround here will be fairly straightforward and should follow what I did here: https://github.com/dotnet/wpf/pull/995/files#diff-7b801941d4352acdc7ea9eeaba96fecd
rladuca commentedon Jul 17, 2019
@stevenbrix Oh I see, so, for instance, I just need to wrap the stream used here instead of the direct cast?
EDIT: Ignore the cast comment, it's just about passing the stream downward, got it.
elyoh commentedon Jul 17, 2019
@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.
weltkante commentedon Jul 17, 2019
@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 fromTextInterface.Factory.CreateFontFace. I'm not sure they have the same root cause, the stack traces sure don't look that way.rladuca commentedon Jul 17, 2019
@weltkante The second stack I posted is the actual exception stack from loading @jbartlau's file with first chance exceptions turned on. Loading the font when the font is located within the XPS always tries to access position, assuming it doesn't live in the root of the archive. Take a look at the offending code in DeobfuscatingStream and you'll see what I am talking about.
I'm pretty sure the root cause of both issues is exactly the same even if the various stacks are slightly different in how we get there.
rladuca commentedon Jul 17, 2019
@weltkante Ah, I see where I might have conflated the two. I assumed the font loading path would get hit both ways. I'll wait for @elyoh's reproduction XPS first.
elyoh commentedon Jul 19, 2019
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 commentedon Jul 19, 2019
@elyoh Thanks! I'll have a look today and see what I can figure out.
rladuca commentedon Jul 19, 2019
@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.
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
rladuca commentedon Jul 19, 2019
Dupe of #585