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

[netcore3] XamlToRtfWriter.WriteShapeImage fails on unseekable streams #858

Closed
grubioe opened this issue Jun 4, 2019 · 2 comments · Fixed by #995
Closed

[netcore3] XamlToRtfWriter.WriteShapeImage fails on unseekable streams #858

grubioe opened this issue Jun 4, 2019 · 2 comments · Fixed by #995
Assignees
Labels
Bug Product bug (most likely)
Milestone

Comments

@grubioe
Copy link
Contributor

grubioe commented Jun 4, 2019

In PresentationFramework (XamlToRtfWriter.cs), the 'WriteShapeImage' function fails to due change in seekability of the zip streams returned in Read mode. The function reads from the same stream twice. This becomes a problem because after the first read, the stream becomes disposed, which causes an exception to be thrown when trying to set the position of the stream back to 0 in order to read the stream again.

Github issue #585 is related to the root cause

Steps to reproduce:

  1. Run DigitalDocuments/...../DrtSequence
  2. Observe following exception thrown when trying to update the stream position in function 'ConvertToImageHexDataString'

System.ObjectDisposedException: 'A stream from ZipArchiveEntry has been disposed.

Object name: 'System.IO.Compression.SubReadStream'.'

@grubioe grubioe added this to the Preview milestone Jun 6, 2019
@grubioe grubioe added the Bug Product bug (most likely) label Jun 6, 2019
@stevenbrix
Copy link
Contributor

stevenbrix commented Jun 17, 2019

Ok, I don't believe the fundamental issue here is that these streams are unseekable, rather it seems that WPF manually closes this stream in the BitmapDownload.ReadCallback method:

 	System.IO.Compression.dll!System.IO.Compression.SubReadStream.Dispose(bool disposing) Line 262
 	System.Private.CoreLib.dll!System.IO.Stream.Close() Line 225
 	System.Private.CoreLib.dll!System.IO.Stream.Dispose() Line 23
 	System.IO.Packaging.dll!System.IO.Packaging.ZipWrappingStream.Dispose(bool disposing) Line 124	
 	System.Private.CoreLib.dll!System.IO.Stream.Close() Line 225
>	PresentationCore.dll!System.Windows.Media.Imaging.BitmapDownload.ReadCallback(System.IAsyncResult result) Line 374
 	System.Private.CoreLib.dll!System.IO.Stream.ReadWriteTask.InvokeAsyncCallback(object completedTask) Line 649
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 172
 	System.Private.CoreLib.dll!System.IO.Stream.ReadWriteTask.System.Threading.Tasks.ITaskCompletionAction.Invoke(System.Threading.Tasks.Task completingTask) Line 675	
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunOrQueueCompletionAction(System.Threading.Tasks.ITaskCompletionAction completionAction, bool allowInlining) Line 3438	
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Line 3356	
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3308	
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishStageThree() Line 2193	
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishStageTwo() Line 2162	
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishSlow(bool userDelegateExecute) Line 2084	
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread) Line 2438	
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteEntryUnsafe(System.Threading.Thread threadPoolThread) Line 2344	
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteFromThreadPool(System.Threading.Thread threadPoolThread) Line 2329
 	System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Line 671	
 	System.Private.CoreLib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() Line 29	

Then we later try to read from the stream and it is disposed at that point

@stevenbrix
Copy link
Contributor

Ahh considering the remarks in MemoryStream since the stream used to behave like a MemoryStream, that calling Close on the stream used to no-op, allowing for future seeks

@ghost ghost locked as resolved and limited conversation to collaborators Apr 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Product bug (most likely)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants