This MSDN article states that X509Store
class implements IDisposable
in .NET 4.5. This was not the case in earlier versions of .NET.
Even though I have Windows 8.1, Visual Studio 2013, all .Net versions installed, from 2.0 to 4.5.1, I can only see X509Store
that looks like .NET 4 version in latest System.dll (v4.0.30319, aka .NET 4.5). VS Object Browser also shows that X509Store
in System.dll v4.0.30319 does not implement IDisposable
like MSDN article says it should.
What am I missing and how do I get X509Store
from .NET 4.5? Is MSDN wrong? It would not be the first time, but still. Is there an obscure Windows Update KB fix for it?
We should use an IDisposable design pattern (or Dispose Pattern) when we need to dispose of unmanaged objects. For implementing the IDisposable design pattern, the class which deals with unmanaged objects directly or indirectly should implement the IDisposable interface.
IDisposable is an interface that contains a single method, Dispose(), for releasing unmanaged resources, like files, streams, database connections and so on.
in a class, you should implement IDisposable and overwrite the Dispose method to allow you to control when the memory is freed. If not, this responsibility is left to the garbage collector to free the memory when the object containing the unmanaged resources is finalized.
Typically, types that use unmanaged resources implement the IDisposable or IAsyncDisposable interface to allow the unmanaged resources to be reclaimed. When you finish using an object that implements IDisposable, you call the object's Dispose or DisposeAsync implementation to explicitly perform cleanup.
At first sight, it looks like that MSDN says the half-truth: Microsoft added IDisposable
interface to the X509Store
class only in 4.6 version, not earlier. You can easily check it by using this really useful diff list between 4.5.2 and 4.6 versions: NET 4.5.2 vs 4.6 - System.Security.Cryptography.X509Certificates namespace.
But at the current moment the MSDN article has the following sentence in the "Remarks" section:
For apps that target the .NET Framework 4.5.2 and earlier versions, the X509Store class does not implement the IDisposable interface and therefore does not have a Dispose method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With