dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.06k stars 1.17k forks source link

XpsDocument.GetFixedDocumentSequence throws an exception #575

Closed jbe2277 closed 5 years ago

jbe2277 commented 5 years ago

Reproduce:

Expected: The Print preview should be shown. You could compare this with the master branch (targets .NET 4.6.1)

Actual: The exception System.Windows.Markup.XamlParseException: 'Add value to collection of type 'System.Windows.Documents.DocumentReferenceCollection' threw an exception.' Line number '1' and line position '136'. ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined. is thrown.

Details: The line FixedDocumentSequence documentSequence = xpsDocument.GetFixedDocumentSequence(); results in the following exception:

System.UriFormatException
  HResult=0x80131537
  Message=Invalid URI: The format of the URI could not be determined.
  Source=System.Private.Uri
  StackTrace:
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)

------ Call stack:
System.Private.Uri.dll!System.Uri.CreateThis(string uri, bool dontEscape, System.UriKind uriKind)
System.Private.Uri.dll!System.Uri.Uri(string uriString)
WindowsBase.dll!MS.Internal.IO.Packaging.PackUriHelper.GetPackageUriComponent(System.Uri packUri)
WindowsBase.dll!MS.Internal.IO.Packaging.PackUriHelper.ValidateAndGetPackUriComponents(System.Uri packUri, out System.Uri packageUri, out System.Uri partUri)
PresentationCore.dll!System.IO.Packaging.PackWebRequestFactory.System.Net.IWebRequestCreate.Create(System.Uri uri)
PresentationCore.dll!System.IO.Packaging.PackWebRequest.GetRequest(bool allowPseudoRequest)
PresentationCore.dll!System.IO.Packaging.PackWebRequest.GetResponse()
PresentationCore.dll!MS.Internal.WpfWebRequestHelper.GetResponse(System.Net.WebRequest request)
PresentationCore.dll!MS.Internal.WpfWebRequestHelper.GetResponseStream(System.Net.WebRequest request, out MS.Internal.ContentType contentType)
PresentationFramework.dll!System.Windows.Documents.DocumentReference._LoadDocument()
PresentationFramework.dll!System.Windows.Documents.DocumentReference.GetDocument(bool forceReload)
PresentationFramework.dll!System.Windows.Documents.FixedDocumentSequence.GetPaginator(System.Windows.Documents.DocumentReference docRef)
PresentationFramework.dll!System.Windows.Documents.FixedDocumentSequence.PageCount.get()
PresentationFramework.dll!System.Windows.Documents.FixedDocumentSequence._OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
[Native to Managed Transition]
[Managed to Native Transition]
System.Xaml.dll!System.Xaml.Schema.SafeReflectionInvoker.InvokeMethodCritical(System.Reflection.MethodInfo method, object instance, object[] args)
System.Xaml.dll!System.Xaml.Schema.XamlTypeInvoker.AddToCollection(object instance, object item)
System.Xaml.dll!MS.Internal.Xaml.Runtime.ClrObjectRuntime.Add(object collection, System.Xaml.XamlType collectionType, object value, System.Xaml.XamlType valueXamlType)
System.Xaml.dll!System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentCollection(MS.Internal.Xaml.Context.ObjectWriterContext ctx)
System.Xaml.dll!System.Xaml.XamlObjectWriter.WriteEndObject()
PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.TransformNodes(System.Xaml.XamlReader xamlReader, System.Xaml.XamlObjectWriter xamlWriter, bool onlyLoadOneNode, bool skipJournaledProperties, bool shouldPassLineNumberInfo, System.Xaml.IXamlLineInfo xamlLineInfo, System.Xaml.IXamlLineInfoConsumer xamlLineInfoConsumer, MS.Internal.Xaml.Context.XamlContextStack<System.Windows.Markup.WpfXamlFrame> stack, System.Windows.Markup.IStyleConnector styleConnector)
PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader xamlReader, System.Xaml.IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, object rootObject, System.Xaml.XamlObjectWriterSettings settings, System.Uri baseUri)
PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader xamlReader, bool skipJournaledProperties, System.Uri baseUri)
PresentationFramework.dll!System.Windows.Markup.XamlReader.Load(System.Xaml.XamlReader xamlReader, System.Windows.Markup.ParserContext parserContext)
PresentationFramework.dll!System.Windows.Markup.XamlReader.Load(System.Xml.XmlReader reader, System.Windows.Markup.ParserContext parserContext, System.Windows.Markup.XamlParseMode parseMode, bool useRestrictiveXamlReader)
PresentationFramework.dll!System.Windows.Markup.XamlReader.Load(System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, bool useRestrictiveXamlReader)
ReachFramework.dll!System.Windows.Xps.Packaging.XpsDocument.GetFixedDocumentSequence()
Waf.Writer.Applications.dll!Waf.Writer.Applications.Controllers.PrintController.ShowPrintPreview()
System.Waf.Core.dll!System.Waf.Applications.DelegateCommand..ctor.AnonymousMethod__0(object p)
System.Waf.Core.dll!System.Waf.Applications.DelegateCommand.Execute(object parameter)
PresentationFramework.dll!MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(System.Windows.Input.ICommandSource commandSource, bool userInitiated)
PresentationFramework.dll!System.Windows.Controls.MenuItem.InvokeClickAfterRender(object arg)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler)
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl()
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj)
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 172
    at F:\workspace\_work\1\s\src\System.Private.CoreLib\shared\System\Threading\ExecutionContext.cs(172)
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke()
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue()
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler)
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)
Writer.dll!Waf.Writer.Presentation.App.Main()
stevenbrix commented 5 years ago

@jbe2277 can you confirm this is still happening in the latest preview? i just tried this out and it doesn't seem to repro with this SDK/runtime combo:

SDK: 3.0.100-preview6-012105 Microsoft.WindowsDesktop.App 3.0.0-preview6-27728-04

jbartlau commented 5 years ago

@stevenbrix I had a repro too, although it might be a different issue as the exception is of a different type. Glad to open separate issue then. I get a NotSupportedException when calling into GetFixedDocumentSequence, Exception details are

System.NotSupportedException
  HResult=0x80131515
  Message=This operation is not supported.
  Source=System.IO.Compression
  StackTrace:
   at System.IO.Compression.DeflateStream.get_Position()
   at System.IO.Packaging.ZipWrappingStream.get_Position()
   at MS.Internal.IO.Packaging.SynchronizingStream.get_Position() in /_/src/Microsoft.DotNet.Wpf/src/shared/MS/Internal/IO/SynchronizingStream.cs:line 207
   at MS.Internal.IO.Packaging.DeobfuscatingStream.Read(Byte[] buffer, Int32 offset, Int32 count) in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Internal/IO/Packaging/DeobfuscatingStream.cs:line 56
   at MS.Internal.FontCache.FontSource.StreamToByteArray(Stream fontStream) in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Internal/FontCache/FontSource.cs:line 419
   at MS.Internal.FontCache.FontSource.GetUnmanagedStream() in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Internal/FontCache/FontSource.cs:line 279
   at MS.Internal.Text.TextInterface.FontFileStream..ctor(IFontSource fontSource)
   at MS.Internal.Text.TextInterface.FontFileLoader.CreateStreamFromKey(Void* fontFileReferenceKey, UInt32 fontFileReferenceKeySize, IntPtr* fontFileStream)

Tested on preview 6. Just let me know if I should open a separate issue for this. I'll then try to minimize my app.

weltkante commented 5 years ago

@jbartlau definitely a different issue, the non-seekable package streams are a known issue (#585) but your particular scenario wasn't mentioned anywhere yet, probably a good idea to add some details there so it doesn't get missed

jbartlau commented 5 years ago

@weltkante Thanks, done.

stevenbrix commented 5 years ago

@jbartlau thanks for letting us know! We'll continue the discussion on #585

ghost commented 5 years ago

This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions!