dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
718 stars 1.56k forks source link

In .NET Framework 4.5.2, X509Certificate2 does implement IDisposable #817

Open michaelmcdaniel opened 6 years ago

michaelmcdaniel commented 6 years ago

I have code that iterates an array of objects that dispose objects that implement IDisposable. In .net 4.5.2, the certificates do in fact get disposed and all references become invalid. I did not check prior versions. The remarks for this class are wrong/misleading and need to be updated.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

rpetrusha commented 6 years ago

@michaelmcdaniel, thanks for your feedback. @bartonjs, the .NET Framework 4 documentation on docs.microsoft.com (but not on MSDN) includes Dispose as inherited from X509Certificate. Can you confirm when IDisposable was first added?

bartonjs commented 6 years ago

IDisposable was added to X509Certificate for .NET Framework 4.6.

Since it's an in-place upgrade with prior 4.x releases, a runtime check will say that it's IDisposable, but at compile-time it can only be used in a using statement when targeting 4.6 or higher.

So, the existing comments are correct, from a compile-time perspective; but a runtime as cares about what version was installed, not what version the compile target was.