Skip to content

The stream was disposed before its real end #17859

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

Open
infofromca opened this issue Apr 27, 2025 · 2 comments · May be fixed by #17860
Open

The stream was disposed before its real end #17859

infofromca opened this issue Apr 27, 2025 · 2 comments · May be fixed by #17860
Labels

Comments

@infofromca
Copy link
Contributor

infofromca commented Apr 27, 2025

Describe the bug

creatingStream was disposed , which made the event hander could not manipulate the stream.

Orchard Core version

latest main

To Reproduce

  1. Go to CreateFileFromStreamAsync of DefaultMediaFileStore
  2. See error
    The stream was not opened for writing.
    or disposed

Expected behavior

Logs and screenshots


2025-04-27 16:06:36.0753|Default|00-2f2c2e1e33d2f3a42eac04632ee95bfd-38307f23cf03942c-00||OrchardCore.Media.Controllers.AdminController|ERROR|An error occurred while uploading a media OrchardCore.FileStorage.FileStoreException: Cannot create file 'zg2/Andy-UX.docx'.
---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.String'.
at Microsoft.AspNetCore.Http.ReferenceReadStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)
at System.IO.Stream.g__Core|27_0(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
at OrchardCore.FileStorage.FileSystem.FileSystemStore.CreateFileFromStreamAsync(String path, Stream inputStream, Boolean overwrite)
--- End of inner exception stack trace ---
at OrchardCore.FileStorage.FileSystem.FileSystemStore.CreateFileFromStreamAsync(String path, Stream inputStream, Boolean overwrite)
at OrchardCore.Media.Core.DefaultMediaFileStore.CreateFileFromStreamAsync(String path, Stream inputStream, Boolean overwrite)
at OrchardCore.Media.Controllers.AdminController.<>c__DisplayClass19_0.<b__1>d.MoveNext() at OrchardCore.FileStorage.FileSystem.FileSystemStore.CreateFileFromStreamAsync(String path, Stream inputStream, Boolean overwrite)
at OrchardCore.Media.Core.DefaultMediaFileStore.CreateFileFromStreamAsync(String path, Stream inputStream, Boolean overwrite)
at OrchardCore.Media.Controllers.AdminController.<>c__DisplayClass19_0.<b__1>d.MoveNext()

@Piedone
Copy link
Member

Piedone commented Apr 30, 2025

Please elaborate what happens before "Go to CreateFileFromStreamAsync of DefaultMediaFileStore". That's in the code; what do you do as a user?

@infofromca
Copy link
Contributor Author

infofromca commented Apr 30, 2025

It is a little complex to explain that.
but main point is that you create 2 event handlers , the first one return the original stream , then run the second one , you will get this error. because of not using:

 // Dispose of the old stream if it was replaced
                        if (creatingStream != resultStream)
                        {
                            creatingStream.Dispose();
                        }

which is on PR now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants