-
-
Notifications
You must be signed in to change notification settings - Fork 733
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
[Bug]: SendFileAsync Dispose()s the provided Stream #2810
Comments
I'm not completely sure, but your code using Stream myImage = File.OpenRead(NAME); is the problem. "using" indicates that it should dispose of itself after the first use. |
Nope.
is equivalent to
is equivalent to
You may use the disposable object as many times as you wish within the HLSSLenda is correct that the culprit is
FileAttachment with its own using . You could probably get around this by constructing your own FileAttachment and passing it in via RespondWithFileAsync(FileAttachment attachment, ... , but this also bypasses the seek so you must also attachment.Stream.Position = 0 in between uses of it unless you actually expect the stream to provide fresh data.
And yea the library probably shouldn't be disposing streams it receives but does not own. Perhaps |
Check The Docs
Verify Issue Source
Check your intents
Description
If I open a
Stream
and I callRespondWithFileAsync
orSendFileAsync
, theStream
gets disposed after Discord.NET sends the message.If the caller allocates or gets somehow a
Stream
, the caller should be responsible for callingDispose
on the stream, not Discord.NET itself.FileAsync wraps the stream under a FileAttachment inside a
using
block, disposing it and theStream
itself at the end of the method (not familiarized enough with Discord.NET code to do a pull request though)Version
3.13.0
Working Version
No response
Logs
Sample
Packages
null
Environment
The text was updated successfully, but these errors were encountered: