From 7dbd2b5325faf1484fb9a5c297d3c19702badc64 Mon Sep 17 00:00:00 2001 From: james7132 Date: Tue, 18 Oct 2016 17:41:32 +0000 Subject: [PATCH] Fix #320 I'm not entirely sure this is the proper way to fix this. However, it seems like SendFileAsync returns the Task, which would exit the using block, disposing of the FileStream potentially before the Task is finished. Changed to await the result of the task before exiting the using block. --- src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index 080ad9779..858269366 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -117,12 +117,12 @@ namespace Discord.Rest return RestUserMessage.Create(client, guild, model); } - public static Task SendFileAsync(IChannel channel, BaseDiscordClient client, + public static async Task SendFileAsync(IChannel channel, BaseDiscordClient client, string filePath, string text, bool isTTS, IGuild guild, RequestOptions options) { string filename = Path.GetFileName(filePath); using (var file = File.OpenRead(filePath)) - return SendFileAsync(channel, client, file, filename, text, isTTS, guild, options); + return await SendFileAsync(channel, client, file, filename, text, isTTS, guild, options).ConfigureAwait(false); } public static async Task SendFileAsync(IChannel channel, BaseDiscordClient client, Stream stream, string filename, string text, bool isTTS, IGuild guild, RequestOptions options)