Skip to content

Commit 142a632

Browse files
committed
Fix as per @edwardneal's suggestion
1 parent c51fb67 commit 142a632

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Fixtures/CertificateFixtureBase.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,22 @@ protected X509Certificate2 CreateCertificate(string subjectName, IEnumerable<str
8686
// This is to ensure that it's imported into the certificate stores with its private key.
8787
using (X509Certificate2 ephemeral = request.CreateSelfSigned(notBefore, notAfter))
8888
{
89-
return X509CertificateLoader.LoadPkcs12(ephemeral.Export(X509ContentType.Pkcs12, password), password,
90-
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable, new Pkcs12LoaderLimits(Pkcs12LoaderLimits.Defaults) { PreserveStorageProvider = true, PreserveKeyName = true });
89+
#if NET9_0_OR_GREATER
90+
return X509CertificateLoader.LoadPkcs12(
91+
ephemeral.Export(X509ContentType.Pkcs12, password),
92+
password,
93+
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable,
94+
new Pkcs12LoaderLimits(Pkcs12LoaderLimits.Defaults)
95+
{
96+
PreserveStorageProvider = true,
97+
PreserveKeyName = true
98+
});
99+
#else
100+
return X509Certificate2(
101+
ephemeral.Export(X509ContentType.Pkcs12, password),
102+
password,
103+
X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
104+
#endif
91105
}
92106
#else
93107
// The CertificateRequest API is available in .NET Core, but was only added to .NET Framework 4.7.2; it thus can't be used in the test projects.

0 commit comments

Comments
 (0)