Some parameters in Stream-derived types are renamed

In .NET 6, some parameters of methods on types derived from System.IO.Stream have been renamed to match the base class.

Change description

In previous .NET versions, several types derived from Stream override methods but use different parameter names than those used by the base type. For example, the byte array parameter of DeflateStream.Read(Byte[], Int32, Int32) is named array while the corresponding argument in the base class method is named buffer.

In .NET 6, all types that derive from System.IO.Stream that had mismatched parameter names have been brought into conformance with the base type by using the same parameter names as the base type.

Version introduced

.NET 6

Reason for change

There are several reasons for the change:

  • 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's impossible for the argument name in the exception to always be correct.
  • Having different parameter names makes it harder to consistently validate behavior across all Stream implementations.
  • .NET 6 adds a public method on Stream for validating arguments, and that methods needs to have a consistent parameter name to use.

The effect of this breaking change is minimal:

  • For existing binaries, its impact is limited to code that uses reflection to examine the names of parameters on the affected derived types.
  • For source code, its impact is limited to code that uses 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.

Affected APIs

See also