@@ -198,7 +198,7 @@ public static void Write(this Stream stream, ReadOnlySpan<byte> buffer)
198
198
/// <typeparam name="T">The type of value to read.</typeparam>
199
199
/// <param name="stream">The source <see cref="Stream"/> instance to read from.</param>
200
200
/// <returns>The <typeparamref name="T"/> value read from <paramref name="stream"/>.</returns>
201
- /// <exception cref="InvalidOperationException ">Thrown if <paramref name="stream"/> reaches the end.</exception>
201
+ /// <exception cref="EndOfStreamException ">Thrown if <paramref name="stream"/> reaches the end.</exception>
202
202
#if NETSTANDARD2_1_OR_GREATER
203
203
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
204
204
#endif
@@ -226,7 +226,7 @@ public static unsafe T Read<T>(this Stream stream)
226
226
// A return value of 0 indicates that the end of the stream has been reached
227
227
if ( bytesRead == 0 )
228
228
{
229
- ThrowInvalidOperationExceptionForEndOfStream ( ) ;
229
+ ThrowEndOfStreamException ( ) ;
230
230
}
231
231
232
232
bytesOffset += bytesRead ;
@@ -246,7 +246,7 @@ public static unsafe T Read<T>(this Stream stream)
246
246
247
247
if ( bytesRead == 0 )
248
248
{
249
- ThrowInvalidOperationExceptionForEndOfStream ( ) ;
249
+ ThrowEndOfStreamException ( ) ;
250
250
}
251
251
252
252
bytesOffset += bytesRead ;
@@ -299,11 +299,13 @@ public static unsafe void Write<T>(this Stream stream, in T value)
299
299
#endif
300
300
}
301
301
302
+ #if ! NET7_0_OR_GREATER
302
303
/// <summary>
303
- /// Throws an <see cref="InvalidOperationException "/> when <see cref="Read{T}"/> fails.
304
+ /// Throws an <see cref="EndOfStreamException "/> when <see cref="Read{T}"/> fails.
304
305
/// </summary>
305
- private static void ThrowInvalidOperationExceptionForEndOfStream ( )
306
+ private static void ThrowEndOfStreamException ( )
306
307
{
307
- throw new InvalidOperationException ( "The stream didn't contain enough data to read the requested item." ) ;
308
+ throw new EndOfStreamException ( "The stream didn't contain enough data to read the requested item." ) ;
308
309
}
310
+ #endif
309
311
}
0 commit comments