Skip to content

Commit 3a38e81

Browse files
authored
Parameters renamed in Stream-derived types (#23126)
1 parent ea14f13 commit 3a38e81

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

docs/core/compatibility/6.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ If you're migrating an app to .NET 6, the breaking changes listed here might aff
2424
## Core .NET libraries
2525

2626
- [Changes to nullable reference type annotations](core-libraries/6.0/nullable-ref-type-annotation-changes.md)
27+
- [Some parameters in Stream-derived types are renamed](core-libraries/6.0/parameters-renamed-on-stream-derived-types.md)
2728
- [Standard numeric format parsing precision](core-libraries/6.0/numeric-format-parsing-handles-higher-precision.md)
2829

2930
## Windows Forms
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "Breaking change: Parameters renamed in Stream-derived types"
3+
description: Learn about the .NET 6.0 breaking change in core .NET libraries where some parameter names in methods of Stream-derived types were changed.
4+
ms.date: 03/04/2021
5+
---
6+
# Some parameters in Stream-derived types are renamed
7+
8+
In .NET 6, some parameters of methods on types derived from <xref:System.IO.Stream?displayProperty=fullName> have been renamed to match the base class.
9+
10+
## Change description
11+
12+
In previous .NET versions, several types derived from <xref:System.IO.Stream> override methods but use different parameter names than those used by the base type. For example, the byte array parameter of <xref:System.IO.Compression.DeflateStream.Read(System.Byte[],System.Int32,System.Int32)?displayProperty=nameWithType> is named `array` while the corresponding argument in the base class method is named `buffer`.
13+
14+
In .NET 6, all types that derive from <xref:System.IO.Stream?displayProperty=fullName> that had mismatched parameter names have been brought into conformance with the base type by using the same parameter names as the base type.
15+
16+
## Version introduced
17+
18+
6.0 Preview 1
19+
20+
## Reason for change
21+
22+
There are several reasons for the change:
23+
24+
- 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.
25+
- Having different parameter names makes it harder to consistently validate behavior across all <xref:System.IO.Stream> implementations.
26+
- .NET 6 adds a public method on <xref:System.IO.Stream> for validating arguments, and that methods needs to have a consistent parameter name to use.
27+
28+
## Recommended action
29+
30+
The effect of this breaking change is minimal:
31+
32+
- For existing binaries, its impact is limited to code that uses reflection to examine the names of parameters on the affected derived types.
33+
- 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.
34+
35+
In both cases, the recommended action is to consistently use the base parameter name.
36+
37+
## Affected APIs
38+
39+
- <xref:System.IO.BufferedStream.Read(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
40+
- <xref:System.IO.BufferedStream.Write(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
41+
- <xref:System.IO.Compression.DeflateStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)?displayProperty=fullName>
42+
- <xref:System.IO.Compression.DeflateStream.Read(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
43+
- <xref:System.IO.Compression.DeflateStream.ReadAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)?displayProperty=fullName>
44+
- <xref:System.IO.Compression.DeflateStream.Write(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
45+
- <xref:System.IO.Compression.DeflateStream.WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)?displayProperty=fullName>
46+
- <xref:System.IO.Compression.GZipStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)?displayProperty=fullName>
47+
- <xref:System.IO.Compression.GZipStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)?displayProperty=fullName>
48+
- <xref:System.IO.Compression.GZipStream.Read(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
49+
- <xref:System.IO.Compression.GZipStream.ReadAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)?displayProperty=fullName>
50+
- <xref:System.IO.Compression.GZipStream.Write(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
51+
- <xref:System.IO.Compression.GZipStream.WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)?displayProperty=fullName>
52+
- <xref:System.IO.FileStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)?displayProperty=fullName>
53+
- <xref:System.IO.FileStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)?displayProperty=fullName>
54+
- <xref:System.IO.FileStream.Read(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
55+
- <xref:System.IO.FileStream.Write(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
56+
- <xref:System.Net.Sockets.NetworkStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)?displayProperty=fullName>
57+
- <xref:System.Net.Sockets.NetworkStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)?displayProperty=fullName>
58+
- <xref:System.Net.Sockets.NetworkStream.Read(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
59+
- <xref:System.Net.Sockets.NetworkStream.ReadAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)?displayProperty=fullName>
60+
- <xref:System.Net.Sockets.NetworkStream.Write(System.Byte[],System.Int32,System.Int32)?displayProperty=fullName>
61+
- <xref:System.Net.Sockets.NetworkStream.WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)?displayProperty=fullName>
62+
63+
<!--
64+
65+
### Category
66+
67+
Core .NET libraries
68+
69+
### Affected APIs
70+
71+
- `M:System.IO.Compression.DeflateStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)`
72+
- `M:System.IO.Compression.DeflateStream.Read(System.Byte[],System.Int32,System.Int32)`
73+
- `M:System.IO.Compression.DeflateStream.ReadAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)`
74+
- `M:System.IO.Compression.DeflateStream.Write(System.Byte[],System.Int32,System.Int32)`
75+
- `M:System.IO.Compression.DeflateStream.WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)`
76+
- `M:System.IO.Compression.GZipStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)`
77+
- `M:System.IO.Compression.GZipStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)`
78+
- `M:System.IO.Compression.GZipStream.Read(System.Byte[],System.Int32,System.Int32)`
79+
- `M:System.IO.Compression.GZipStream.ReadAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)`
80+
- `M:System.IO.Compression.GZipStream.Write(System.Byte[],System.Int32,System.Int32)`
81+
- `M:System.IO.Compression.GZipStream.WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)`
82+
- `M:System.IO.BufferedStream.Read(System.Byte[],System.Int32,System.Int32)`
83+
- `M:System.IO.BufferedStream.Write(System.Byte[],System.Int32,System.Int32)`
84+
- `M:System.IO.FileStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)`
85+
- `M:System.IO.FileStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)`
86+
- `M:System.IO.FileStream.Read(System.Byte[],System.Int32,System.Int32)`
87+
- `M:System.IO.FileStream.Write(System.Byte[],System.Int32,System.Int32)`
88+
- `M:System.Net.Sockets.NetworkStream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)`
89+
- `M:System.Net.Sockets.NetworkStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)`
90+
- `M:System.Net.Sockets.NetworkStream.Read(System.Byte[],System.Int32,System.Int32)`
91+
- `M:System.Net.Sockets.NetworkStream.ReadAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)`
92+
- `M:System.Net.Sockets.NetworkStream.Write(System.Byte[],System.Int32,System.Int32)`
93+
- `M:System.Net.Sockets.NetworkStream.WriteAsync(System.Byte[],System.Int32,System.Int32,System.Threading.CancellationToken)`
94+
95+
-->

docs/core/compatibility/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ items:
4343
items:
4444
- name: Nullability annotation changes
4545
href: core-libraries/6.0/nullable-ref-type-annotation-changes.md
46+
- name: Parameters renamed in Stream-derived types
47+
href: core-libraries/6.0/parameters-renamed-on-stream-derived-types.md
4648
- name: Standard numeric format parsing precision
4749
href: core-libraries/6.0/numeric-format-parsing-handles-higher-precision.md
4850
- name: Windows Forms
@@ -441,6 +443,8 @@ items:
441443
items:
442444
- name: Nullability annotation changes
443445
href: core-libraries/6.0/nullable-ref-type-annotation-changes.md
446+
- name: Parameters renamed in Stream-derived types
447+
href: core-libraries/6.0/parameters-renamed-on-stream-derived-types.md
444448
- name: Standard numeric format parsing precision
445449
href: core-libraries/6.0/numeric-format-parsing-handles-higher-precision.md
446450
- name: .NET 5

0 commit comments

Comments
 (0)