Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent error "The system cannot find the file specified" when instantiating X509Certificate2 #9242

Open
silvairsoares opened this issue Mar 26, 2024 · 0 comments

Comments

@silvairsoares
Copy link

URL(s)

https://github.com/dotnet/core/blob/main/release-notes/6.0/6.0.0/6.0.0.md

Description

I have this method in a .NET (net6.0) application, to instantiate and return a digital certificate.

using framework.mstiCSharp.Extensions;
using System;
using System.Security.Cryptography.X509Certificates;

namespace msti.newpro.Core.Services.ADMServices.Services
{
     public static class DigitalServices Certificate
     {
         public static X509Certificate2 GetX509Certificate2(string Base64Certificate, string Password)
         {
             try
             {
                 byte[] decodedByteArray = Convert.FromBase64String(Base64Certificate);
                 return new X509Certificate2(decodedByteArray, Password);
             }
             catch (Exception ex)
             {
                 throw new Exception("Error loading digital certificate: " + ex.GetAllInnerExceptionMessage() + "\n"+ "Base64: "+ Base64Certificate);
             }
         }
     }
}

Most of the time, it works fine. But sometimes and only sometimes, it throws the exception:

"The system cannot find the file specified"

I generated logs of the input parameters (Base64Certificate string, Password string) and there is no problem with them, they always have the expected values.

In the testing environment and on my local computer, we never had the problem. But in production, on an AWS EC2, running Windows Server 2019, we sometimes have this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant