DbDataReader.Close() doesn't unify with System.Data.Common
If I write a provider against System.Data.Common on .NET Standard 1.2 and implement Dispose appropriately, then I try to use that provider on .NET Framework 4.6 or .NET Core 2.0, the following code won't work.
reader.Close(); // No-op
Assert.True(reader.IsClosed); // Fails since Dispose is never called
It fails because on .NET Framework and .NET Core 2.0, Dispose calls Close (not the other way around) and since there is no virtual Close method on .NET Standard 1.2, I cannot override it without cross-targeting the frameworks that do have it.
/cc @YoungGah @saurabh500
@bricelam: It is not ideal that Dispose calls Close but unfortunately that is how Dispose is implemented on NET Framework. As for Close being removed from DbDataReader, we carefully reviewed all Close methods under System.Data.Common as Close is a synonym for Dispose. We concluded that Close on DbDataReader is redundant and does not provide any additional value unlike Close method on DbConnection. Close method on DbConnection is appropriate as DBConnection has Open method.
This issue is not ideal, but given that the recommendation is for users to call Dispose method by "using" statement with DbDataReader, we won't be fixing this issue.
I'm re-opening this because it is a real issue for provider writers that prevents them from (responsibly) creating a provider that just targets .NET Standard 1.2 (without cross-targeting .NET Framework 4.5.1).
IMHO, the solution here is to add Close() back to DbDataReader in .NET Standard 1.2 (as we're doing in .NET Standard 2.0)
cc @divega
Maybe even put [EditorBrowsable(EditorBrowsableState.Never)] on it so users won't call it, but provider writers can provide a correct implementation.
This issue now appears on netstandard2.0 and netcoreapp2.0 (in addition to net4x). Because DbDataReader.Close() has been added back, you can write the code above, but if a netstandard1.x provider hasn't worked around it by corss-targeting net4x and netstandard2.0 now, calling Close() is a no-op.
I have looked at SqlDataReader, DataTableReader and OdbcDataReader and they all have Close() implemented and Dispose is calling into Close()
For DbDataReader there is not logic in Close() on Desktop which I believe is expected since this is abstract class.
Can this be closed or am I missing something?
This is an issue in the .NET Standard 1.2 System.Data.Common contract that has since been fixed in 2.0. This issue is tracking whether we should backport the fix (add a virtual Close method to DbDataReader) into the .NET Standard 1.2 System.Data.Common contract. @divega, @terrajobst, @ericstj, et al. are currently investigating whether this is feasible.
(I've updated the main description to better articulate the issue.)
I've assigned them to this task since they are working on it
/cc @weshaggard
I would imagine that is possible if you rebuild the ns1.2 ref and ensure that all implementations have the Close method (including those where it is inbox like xamarin). It doesn't appear to be inbox anywhere else (Desktop, .NET Core, UAP) so it seems feasible.
This is actually the first I've heard of this, but I think the right course of action would be for the folks who own Data.Common to propose a solution, test that on all frameworks, then take the change to FxDC if it involves any API changes.
@bricelam @karelz this is neither a netcoreapp nor a 2.0 issue but affects it. I suggest moving it to netstandard and mark it as critical production issue.
@ViktorHofer this isn't something that would be fixed in the standard repo. If we were to take a fix for this, which I'm not convinced we should, then it would need to happen in the corefx repo.
I see, thanks for enlighten me
As of tomorrows ZBB, we need to make the decision of either ignoring the issue for 2.0 or fixing it. @danmosemsft @weshaggard @karelz
@saurabh500 @corivera @ericstj can you please chime in?
We've already added the Close() API in 2.0.0, so this just seems like a 1.2 servicing issue.
Which servicing branch does it live in? 1.0.x or 1.1.x - can you please set the milestone to match that?
According to @weshaggard we would have to make changes in 1.1.0
Actually, looks like DbDataReader.Close() was already added to 1.1.0 in this commit: https://github.com/dotnet/corefx/commit/27240e90597d477c213b0af81142e6b53b6ea315#diff-7ce02b6f11b3db97a63d932124bd3cdaR288