Azure / Azure/azure-functions-host
After switching to new DI, getting Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
We just switched over to the new DI pattern in our Functions. Code that was working previously, is now failing. In our code, we decrypt data using X.509 certificates installed in the function. The same exact code is running in our App Service, and never fails. The code is very basic, and I have used it for years.
In functions, it throws an
> Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException
The inner most message says
> "The system cannot find the file specified."
We have put in a ticket to look into this, but we suspect the issue arises when a new instance is spun up. We have seen this happen in a few functions, so it is not isolated.
We have retry logic, but the problem with the retry is you cannot catch this specific exception so the message dead letters.
The suspected issue is coming from this code:
```
Store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection col = Store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
```
The error will continue to throw for about 40 minutes to several hours. Once the load decreases, the issue resolves (best guess). However, a restart always fixes the issue.
Please let me know if you need any additional details.
Contributor guide
Research direction
Start with the certificate-store calls shown in the report—Store.Open and Store.Certificates.Find—and compare their behavior during a new instance under load. Reproduce the WindowsCryptographicException, then determine why restart or reduced load changes it and document a reliable fix; no repository file or test is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- backend, cloud, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100