This change fixes a bug where the disposal of an X509Certificate2 instance causes the subsequent disposal (removal) of that certificate's trust because the TrustedTestCert<X509Certificate2> instance references the same certificate instance. When the X509Certificate2 instance is disposed, TrustedTestCert<X509Certificate2> cannot remove the certificate from the root store because its certificate reference is disposed.
The fix is to only dispose the TrustedTestCert<X509Certificate2> instance.
Summary of the changes (in less than 80 characters):
This change ensures that test certificates are removed from the root store.
Addresses https://github.com/NuGet/NuGetGallery/issues/10259
Details
This change fixes a bug where the disposal of an
X509Certificate2
instance causes the subsequent disposal (removal) of that certificate's trust because theTrustedTestCert<X509Certificate2>
instance references the same certificate instance. When theX509Certificate2
instance is disposed,TrustedTestCert<X509Certificate2>
cannot remove the certificate from the root store because its certificate reference is disposed.The fix is to only dispose the
TrustedTestCert<X509Certificate2>
instance.