- SonarQube Enterprise Edition Version 8.3.1 (build 34397)
- minimal code sample to reproduce (.NET Core 3.1, C#8):
{
await using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"ThePath.{path}");
using var reader = new StreamReader(stream); // Refactor this code to make sure 'stream' is disposed only once.
return await reader.ReadToEndAsync().ConfigureAwait(false);
}
This seems wrong - Dispose on the stream reader will not dispose the stream.
With the ‘old’ C# syntax the S3966 warning is not shown,
internal static async Task<string> ReadDataFromFileAsync(string path)
{
await using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"ThePath.{path}");
using (var reader = new StreamReader(stream))
return await reader.ReadToEndAsync().ConfigureAwait(false);
}