Closed
Description
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)
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);