Skip to content

Parameter names on some Stream-derived types renamed to be consistent with the base type #23102

@stephentoub

Description

@stephentoub

Version introduced

.NET 6 Preview 1

Old behavior

Several types derived from System.IO.Stream overrode methods with different parameter names than was used by the base type. For example, DeflateStream.Read's byte[] argument was named array even though the base Stream.Read's corresponding argument is named buffer.

New behavior

All System.IO.Stream types that had such mismatched parameter names have been brought into conformance with the base type, using the same parameter names on the derived types as on the base type.

Reason for change

There are several reasons for the change:

  1. If an invalid argument was passed and an exception was thrown, that exception might have contained the base parameter's name or the derived parameter's name, depending on the implementation. Since the caller may have been using a reference typed as the base or as the derived type, it is impossible for the argument name in the exception to always be correct.
  2. Having different parameter names makes it harder to consistently validate behavior across all Stream implementations.
  3. .NET 6 adds a public method on Stream for validating arguments, and it needs to have a consistent name it can use.

Recommended action

The effect of this breaking change is minimal:

  1. For existing binaries, its impact is limited to code using reflection to examine the names of parameters on the derived types.
  2. For source code, its impact is limited to code using named parameters to invoke methods on the derived stream type using a variable typed as that derived type.

In both cases, the recommended action is to consistently use the base parameter name.

Category

  • ASP.NET Core
  • C#
  • Code analysis
  • Core .NET libraries
  • Cryptography
  • Data
  • Debugger
  • Deployment
  • Globalization
  • Interop
  • JIT
  • LINQ
  • Managed Extensibility Framework (MEF)
  • MSBuild
  • Networking
  • Printing
  • Security
  • Serialization
  • Visual Basic
  • Windows Forms
  • Windows Presentation Foundation (WPF)
  • XML, XSLT

Issue metadata

  • Issue type: breaking-change

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 6Issues and PRs for the .NET 6 releasebreaking-changeIndicates a .NET Core breaking change

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions