-
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
.NET 6 FileStream fails with System.IO.IOException: 'The parameter is incorrect' when FILE_FLAG_NO_BUFFERING used #62851
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsDescriptionNew .NET 6 FileStream has got unexpected behavior that was not present in all previous .NET frameworks starting from at least .NETFX 2. There appears to be an exception System.IO.IOException: 'The parameter is incorrect' thrown after whole file is read if the file is not a multiple of read buffer size Reproduction Steps// .NET 6 console code to repro // test 1: multiple of buffer reads: works in all .NET's // test 2: slightly larger size of file: fails in .NET 6 new FileStream object, works if config uses: "System.IO.UseNet5CompatFileStream": true void TestReads(int iDataSize)
} Console.WriteLine("done"); Expected behaviorShould work by returning 0 read bytes on last call, just like in all previous frameworks (including .NET 5). Actual behaviorOn second test Throws System.IO.IOException: 'The parameter is incorrect' Regression?Yes - worked in all previous Frameworks including FX since 2.0 Known WorkaroundsTurning off new .NET 6 FileStream object in app config HOWEVER that option is said to be removed in .NET 7 and it means that benefits of new implementation are not used.
It's also possible to check file size before reading and use that to avoid making last call that should have just read 0 bytes, BUT that is ugly and unnecessary, there just should be no exception thrown. Configuration.NET 6, current Windows 10 on x64, using Console app build. Other informationDetailed exception thrown - System.IO.IOException at Program.$(String[] args) in C:\Users\Alex\source\repos\FileStreamBug\Program.cs:line 8
|
@adamsitnik - this sounds good to me, thank you for fixing this very important to us bug. We'll use .NET 5 Stream fallback option for the time being, that seems to work well, closing this issue now. I'll check out that other link for feedback. |
@HighPerfDotNet I am going to close the issue once the PR gets merged. Thank you for your feedback! |
#63625 got merged, the fix will be shipped as part of .NET 7 Preview 1 |
Description
New .NET 6 FileStream has got unexpected behavior that was not present in all previous .NET frameworks starting from at least .NETFX 2. There appears to be an exception System.IO.IOException: 'The parameter is incorrect' thrown after whole file is read if the file is not a multiple of read buffer size
Reproduction Steps
Expected behavior
Should work by returning 0 read bytes on last call, just like in all previous frameworks (including .NET 5).
Actual behavior
On second test Throws System.IO.IOException: 'The parameter is incorrect'
Regression?
Yes - worked in all previous Frameworks including FX since 2.0
Known Workarounds
Turning off new .NET 6 FileStream object in app config HOWEVER that option is said to be removed in .NET 7 and it means that benefits of new implementation are not used.
It's also possible to check file size before reading and use that to avoid making last call that should have just read 0 bytes, BUT that is ugly and unnecessary, there just should be no exception thrown.
Configuration
.NET 6, current Windows 10 on x64, using Console app build.
Other information
The text was updated successfully, but these errors were encountered: