Skip to content

StreamWriter constructor documentation mismatch with implementation #106237

@rameel

Description

@rameel

There is an inconsistency between the documentation and the actual implementation of the StreamWriter 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 StreamWriter(Stream stream, Encoding encoding)
    : this(stream, encoding, DefaultBufferSize, false);

public StreamWriter(Stream stream, Encoding encoding, int bufferSize)
    : this(stream, encoding, bufferSize, false);
public StreamWriter(Stream stream, Encoding? encoding = null, int bufferSize = -1, bool leaveOpen = false);

StreamWriter.cs
Documentation

Suggested Fix:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-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