dotnet-api-docs
dotnet-api-docs copied to clipboard
StreamWriter(Stream, Encoding, Int32, Boolean) does not throw for null Encoding on all runtimes
Type of issue
Outdated article
Description
StreamWriter(Stream, Encoding, Int32, Boolean) does not throw for null Encoding on .NET 6.0, .NET 8.0 and .NET 9.0-preview.7.
It seems to only throw on .NET Framework.
Page URL
https://learn.microsoft.com/en-us/dotnet/api/system.io.streamwriter.-ctor?view=net-9.0#system-io-streamwriter-ctor(system-io-stream-system-text-encoding-system-int32-system-boolean)
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.IO/StreamWriter.xml
Document Version Independent Id
ba32d206-d8f5-fd4d-939b-16d19e9b10ac
Article author
@dotnet-bot
This seems to be by design of StreamWriter. The code defaults to UTF8NoBOM
https://github.com/dotnet/runtime/blob/6072e4d3a7a2a1493f514cdf4be75a3d56580e84/src/libraries/System.Private.CoreLib/src/System/IO/EncodingCache.cs#L10
https://github.com/dotnet/runtime/blob/5f067ce8b50087e032d13a1b97ae5ec39fc54739/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs#L75-L131
We should update the docs to reflect this. (also, the nullability annotations in the source code are inconsistent for the Encoding parameter across ctor overloads.
@rzikm,
This seems to be by design of StreamWriter. The code defaults to
UTF8NoBOMhttps://github.com/dotnet/runtime/blob/6072e4d3a7a2a1493f514cdf4be75a3d56580e84/src/libraries/System.Private.CoreLib/src/System/IO/EncodingCache.cs#L10
https://github.com/dotnet/runtime/blob/5f067ce8b50087e032d13a1b97ae5ec39fc54739/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs#L75-L131
We should update the docs to reflect this. (also, the nullability annotations in the source code are inconsistent for the Encoding parameter across ctor overloads.
It's different between .NET Framework and .NET.
I don't know how we are going to document this, but it makes .NET Standard 2.0 inconsistent across runtimes.