Skip to content

StreamReader constructor documentation mismatch with implementation #106236

Closed
@rameel

Description

@rameel

There is an inconsistency between the documentation and the actual implementation of the StreamReader constructors. The documentation states that passing null to the Encoding parameter in some constructors, except the main one, will result in an exception being thrown. However, all these constructors pass the Encoding argument to the main constructor, which allows null.

public StreamReader(Stream stream, Encoding encoding);
public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks);
public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize);
public StreamReader(Stream stream, Encoding? encoding = null, bool detectEncodingFromByteOrderMarks = true, int bufferSize = -1, bool leaveOpen = false)

StreamReader.cs
Documentation

Suggested Fix:

  • Mark the Encoding parameter as nullable in these constructors.
  • Update the documentation.
- public StreamReader(Stream stream, Encoding encoding);
- public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks);
- public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize);
+ public StreamReader(Stream stream, Encoding? encoding);
+ public StreamReader(Stream stream, Encoding? encoding, bool detectEncodingFromByteOrderMarks);
+ public StreamReader(Stream stream, Encoding? encoding, bool detectEncodingFromByteOrderMarks, int bufferSize);

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.IOhelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions