Skip to content

IOException in ZipArchiveEntry.OpenInUpdateMode when printing #6842

Description

@bgrainger
  • .NET Core Version: Microsoft.NETCore.App 6.0.7
  • Windows version: Windows 10 21H2 x64, 19044.1826
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: No
  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No

Problem description:

In a WPF application ported to .NET 6.0 from .NET Framework 4.7.2, printing a complex document throws an exception, and nothing prints. (The Microsoft Print to PDF driver writes a 0-byte file.)

At the moment, I don't have a self-contained repro, but reporting the call stack as part of starting the investigation, and in case anyone else has relevant information.

Actual behavior:

System.IO.IOException: 'Entries cannot be opened multiple times in Update mode.'

System.IO.Compression.dll!System.IO.Compression.ZipArchiveEntry.OpenInUpdateMode() Line 699	C#
System.IO.Compression.dll!System.IO.Compression.ZipArchiveEntry.Open() Line 297	C#
System.IO.Packaging.dll!System.IO.Packaging.ZipStreamManager.Open(System.IO.Compression.ZipArchiveEntry zipArchiveEntry, System.IO.FileMode streamFileMode, System.IO.FileAccess streamFileAccess) Line 85	C#
System.IO.Packaging.dll!System.IO.Packaging.ZipPackagePart.GetStreamCore(System.IO.FileMode streamFileMode, System.IO.FileAccess streamFileAccess) Line 45	C#
System.IO.Packaging.dll!System.IO.Packaging.PackagePart.GetStream(System.IO.FileMode mode, System.IO.FileAccess access) Line 320	C#
WindowsBase.dll!MS.Internal.IO.Packaging.PackagePartExtensions.GetSeekableStream(System.IO.Packaging.PackagePart packPart, System.IO.FileMode mode, System.IO.FileAccess access) Line 62	C#
PresentationCore.dll!System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream() Line 652	C#
PresentationCore.dll!System.IO.Packaging.PackWebResponse.GetResponseStream() Line 273	C#
PresentationCore.dll!MS.Internal.WpfWebRequestHelper.CreateRequestAndGetResponseStream(System.Uri uri) Line 180	C#
ReachFramework.dll!System.Windows.Xps.Serialization.ImageSourceTypeConverter.ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) Line 245	C#
ReachFramework.dll!System.Windows.Xps.Serialization.VisualSerializer.WriteBitmap(string attribute, System.Windows.Media.ImageSource imageSource) Line 647	C#
ReachFramework.dll!System.Windows.Xps.Serialization.VisualSerializer.BrushToString(System.Windows.Media.Brush brush, System.Windows.Rect bounds) Line 774	C#
ReachFramework.dll!System.Windows.Xps.Serialization.VisualSerializer.FindBrush(System.Windows.Media.Brush brush, System.Windows.Rect bounds) Line 273	C#
ReachFramework.dll!System.Windows.Xps.Serialization.VisualSerializer.WriteBrush(string attribute, System.Windows.Media.Brush brush, System.Windows.Rect bounds) Line 905	C#
ReachFramework.dll!System.Windows.Xps.Serialization.VisualSerializer.System.Windows.Xps.Serialization.IMetroDrawingContext.DrawGeometry(System.Windows.Media.Brush brush, System.Windows.Media.Pen pen, System.Windows.Media.Geometry geometry) Line 1925	C#
ReachFramework.dll!System.Windows.Xps.Serialization.DrawingContextFlattener.DrawGeometry(System.Windows.Media.Brush brush, System.Windows.Media.Pen pen, System.Windows.Media.Geometry geometry) Line 283	C#
ReachFramework.dll!System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(System.Windows.Media.Drawing d, System.Windows.Media.Matrix drawingToWorldTransform) Line 699	C#
ReachFramework.dll!System.Windows.Xps.Serialization.VisualTreeFlattener.DrawingWalk(System.Windows.Media.Drawing d, System.Windows.Media.Matrix drawingToWorldTransform) Line 761	C#
ReachFramework.dll!System.Windows.Xps.Serialization.VisualTreeFlattener.StartVisual(System.Windows.Media.Visual visual) Line 641	C#
ReachFramework.dll!System.Windows.Xps.Serialization.ReachVisualSerializerAsync.SerializeNextTreeNode(System.Windows.Xps.Serialization.ReachVisualSerializerContext context) Line 174	C#
ReachFramework.dll!System.Windows.Xps.Serialization.ReachVisualSerializerAsync.AsyncOperation(System.Windows.Xps.Serialization.ReachSerializerContext context) Line 73	C#
ReachFramework.dll!System.Windows.Xps.Serialization.XpsOMSerializationManagerAsync.InvokeSaveAsXamlWorkItem(object arg) Line 148	C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 103	C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 36	C#
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() Line 540	C#
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) Line 489	C#
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) Line 215	C#
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 183	C#
System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 148	C#
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 172	C#
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Line 412	C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Line 2087	C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Line 2296	C#
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Line 295	C#
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Line 429	C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 103	C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 36	C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Line 1329	C#
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Line 341	C#
[Native to Managed Transition]	
[Managed to Native Transition]	
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Line 2135	C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) Line 329	C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() Line 297	C#
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Line 2405	C#
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Line 1695	C#
PresentationFramework.dll!System.Windows.Application.Run() Line 198	C#

Expected behavior:

Printing works without exception.

Minimal repro:

N/A

Activity

  1. bgrainger commented on Jul 23, 2022

    @bgrainger
    ContributorAuthor

    Exception call stack ends in the same stack as #3206, but it's not clear to me yet if the issues are related.

  2. added a commit that references this issue on Jul 23, 2022
    cac4206
  3. added
    needs more information
    and removed on Jul 25, 2022
  4. gurpreet-wpf commented on Jul 25, 2022

    @gurpreet-wpf
    Contributor

    @bgrainger Could you please attach the sample repro for this issue. Meanwhile, we would be looking at the PR and check to see if the problem and solution match.

  5. bgrainger commented on Jul 25, 2022

    @bgrainger
    ContributorAuthor

    The application where I encountered this problem is not one I can attach to this issue.

    I have not yet been able to create a smaller repro for it, but will attach one as soon as I can.

  6. anjaligupta-dev commented on Sep 12, 2022

    @anjaligupta-dev

    @bgrainger closing this for now, create a new issue when sample app is ready.

  7. lindexi commented on Sep 21, 2022

    @lindexi
    Member

    It seems that the WpfWebRequestHelper.CreateRequestAndGetResponseStream request the stream and the stream do not be closed.

    Stream srcStream = MS.Internal.WpfWebRequestHelper.CreateRequestAndGetResponseStream(sourceUri);
    CopyImageStream(srcStream, resourceStream.Stream);
    srcStream.Close();

  8. lindexi commented on Sep 21, 2022

    @lindexi
    Member

    I find this issues in my computer. The CopyImageStream throw the OutOfMemoryException. And then the ZipArchiveEntry throw the exception like this.

  9. lindexi commented on Sep 21, 2022

    @lindexi
    Member

    @anjalisheel-wpf Can we re-open this issues?

  10. pchaurasia14 commented on Sep 21, 2022

    @pchaurasia14
    Contributor

    @lindexi - Are you able to reproduce the issue in a standalone application ?

  11. lindexi commented on Sep 22, 2022

    @lindexi
    Member

    @pchaurasia14 Sorry, I can not reproduce the issue in a standalone application. But I found a step that might reproduce the issue.

    The step is: consumes all computer memory!

    Yes, Repeat the above steps several times, and wait the CopyImageStream method throw the OutOfMemoryException

  12. ghost locked as resolved and limited conversation to collaborators on Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs more information

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions