Skip to content
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

Disable Net5CompatFileStream by default #50166

Merged
merged 8 commits into from
Apr 8, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void LegacySwitchIsHonored()
.GetField("_strategy", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(fileStream);

Assert.DoesNotContain("Net5Compat", strategy.GetType().FullName);
Assert.Contains("Net5Compat", strategy.GetType().FullName);
}

File.Delete(filePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"configProperties": {
"System.IO.UseNet5CompatFileStream": false
"System.IO.UseNet5CompatFileStream": true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"configProperties": {
"System.IO.UseNet5CompatFileStream": false
"System.IO.UseNet5CompatFileStream": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,7 @@ namespace System.IO.Strategies
{
internal static partial class FileStreamHelpers
{
// It's enabled by default. We are going to change that once we fix #16354, #25905 and #24847.
internal static bool UseNet5CompatStrategy { get; } = GetNet5CompatFileStreamSetting();

private static bool GetNet5CompatFileStreamSetting()
{
if (AppContext.TryGetSwitch("System.IO.UseNet5CompatFileStream", out bool fileConfig))
{
return fileConfig;
}

string? envVar = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_IO_USENET5COMPATFILESTREAM");
return envVar is null
? true // Net5Compat is currently enabled by default;
: bool.IsTrueStringIgnoreCase(envVar) || envVar.Equals("1");
}
internal static bool UseNet5CompatStrategy { get; } = AppContextConfigHelper.GetBooleanConfig("System.IO.UseNet5CompatFileStream", "DOTNET_SYSTEM_IO_USENET5COMPATFILESTREAM");

internal static FileStreamStrategy ChooseStrategy(FileStream fileStream, SafeFileHandle handle, FileAccess access, FileShare share, int bufferSize, bool isAsync)
=> WrapIfDerivedType(fileStream, ChooseStrategyCore(handle, access, share, bufferSize, isAsync));
Expand Down