X509Certificate2.Reset Method

Namespace: System.Net.Security
Assembly: System.Security.Cryptography.X509Certificates.dll

Syntax

public void Reset();

Description

Resets all properties of the current X509Certificate2 object to their default values. This method is useful when you need to clear all cached information about the certificate, such as its decoded properties or any extensions, and re-evaluate them when they are next accessed.

Calling Reset() discards any previously parsed or cached data associated with the certificate. Subsequent access to properties like SubjectName, IssuerName, or Extensions will trigger a re-parsing of the certificate data.

Parameters

This method does not take any parameters.

Return Value

This method does not return a value.

Remarks

Exceptions

This method does not throw any exceptions.

Requirements

Example

using System; using System.Security.Cryptography.X509Certificates; public class Example { public static void Main(string[] args) { // Assume cert is a valid X509Certificate2 object X509Certificate2 cert = new X509Certificate2("mycert.cer"); // Access a property to populate cache string subject = cert.SubjectName.Name; Console.WriteLine($"Initial Subject: {subject}"); // Reset the certificate's cached properties cert.Reset(); Console.WriteLine("Certificate properties have been reset."); // Accessing the property again will re-parse the data string newSubject = cert.SubjectName.Name; Console.WriteLine($"Subject after reset: {newSubject}"); } }