|
| 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 | +--> |
0 commit comments