[CSHARP-4377] GridFSDownloadStream.Flush must not throw NotSupportedException Created: 22/Oct/22  Updated: 28/Oct/23  Resolved: 24/Nov/22

Status: Closed
Project: C# Driver
Component/s: GridFS
Affects Version/s: None
Fix Version/s: 2.19.0

Type: Bug Priority: Unknown
Reporter: Robin Boerdijk Assignee: James Kovacs
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-1488 Properly implement Flush/FlushAsync f... Closed
Backwards Compatibility: Minor Change

 Description   

Summary

The Flush method of GridFSDownloadStream throws NotSupportedException. This is incorrect according to the .NET System.IO.Stream.Flush man page at https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.flush?view=net-6.0.

The man page states: "In a class derived from Stream that doesn't support writing, Flush is typically implemented as an empty method to ensure full compatibility with other Stream types since it's valid to flush a read-only stream."

See below for a real-life case where this is a problem

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

2.17.1

How to Reproduce

Pass a GridFSDownloadStream as input stream to a .NET CryptoStream in read mode. The CryptoStream's Dispose() method calls Flush() on the input stream, which causes the NotSupportedException to be thrown.

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by Githook User [ 24/Nov/22 ]

Author:

{'name': 'James Kovacs', 'email': 'jkovacs@post.harvard.edu', 'username': 'JamesKovacs'}

Message: CSHARP-4377: Flush on read-only stream should be a NOP. (#971)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/1446eacb965605fb4b7c7a65a7c511a380bdd546

Generated at Wed Feb 07 21:48:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.