-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Regression: ObjectDisposedException in overridden FileStream.Dispose(bool disposing) #82186
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsDescriptionIf you have a class derived from FileStream that overrides Reproduction Stepsusing System;
using System.IO;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
await using MyStream file = new(Path.GetTempFileName(), FileMode.Open);
}
}
class MyStream : FileStream
{
private bool _isDisposed;
public MyStream(string path, FileMode mode) : base(path, mode)
{
}
protected override void Dispose(bool disposing)
{
if (!_isDisposed)
{
Console.WriteLine("Dispose({0}) called. Length {1}.", disposing, Length);
_isDisposed = true;
}
base.Dispose(disposing);
}
} Expected behavior
Actual behavior
Regression?Worked in .NET Core 3.1, .NET 5 and .NET 6 prior to 6.0.14 release Known WorkaroundsOverride DisposeAsync Configuration.NET 6.0.14 Other informationThis is similar to #82176 (probably has the same root cause), but it demonstrates that the obvious workaround (override
|
cc: @adamsitnik |
In your code you're reading |
Oh, wait, it's calling it with true... you logged that. Huh. |
Prior to .NET 6.0.14 it was calling with true. |
Description
If you have a class derived from FileStream that overrides
void Dispose(bool disposing)
and accesses the Length property, you'll get an ObjectDisposedException when the stream is disposed asynchronously via IAsyncDisposable.DisposeAsync (await using ...
)Reproduction Steps
Expected behavior
Actual behavior
Regression?
Worked in .NET Core 3.1, .NET 5 and .NET 6 prior to 6.0.14 release
Known Workarounds
Override DisposeAsync
Configuration
.NET 6.0.14
Windows 11
x64
Other information
This is similar to #82176 (probably has the same root cause), but it demonstrates that the obvious workaround (override
Dispose(bool disposing)
) isn't sufficient.The text was updated successfully, but these errors were encountered: