Table of Contents
Which file should the system find? What are we talking about?
As I have often said, in a development, test (demo), (recently no longer acceptance), and production environment.
Because we wanted to be able to deploy an environment with 1 push of a button, we now have the option to deploy our own development environment.
This required some research, because you want as much of a copy of the production environment as possible.
We managed to roll out a dev environment and everything seemed to be going well, until we ran into the problem below.
I’m not an expert in the field of web service, and you probably aren’t either, otherwise you wouldn’t be here! It’s simpeler than you think.
What environment are we talking about?
For IIS it’s best to follow this link to StackOverflow:
c# – CryptographicException was unhandled: System cannot find the specified file – Stack Overflow
For Azure Web Services you can follow the tutorial.
Simply put, in my case, the certificate cannot be found, because there was no location to save the certificate and, when downloaded, it cannot, but I did not receive an error when trying to download the certificate!
To be able to use things like this, you can enable an environment variable called WEBSITE_LOAD_USER_PROFILE and set the value to 1.
Go to your Azure Web App > Environment Variables > Add WEBSITE_LOAD_USER_PROFILE and set the value to 1.

You should be able to use certificates now. I tried to find more information regarding the environment variable, and I found the following information:
- Use a TLS/SSL certificate in code – Azure App Service | Microsoft Learn
- Environment variables and app settings reference – Azure App Service | Microsoft Learn
Complete error message
System.Security.Cryptography.CryptographicException: The system cannot find the file specified.
at System.Security.Cryptography.X509Certificates.CertificatePal.FilterPFXStore(ReadOnlySpan1 rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags) at System.Security.Cryptography.X509Certificates.CertificatePal.FromBlobOrFile(ReadOnlySpan1 rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.CertificatePal.FromBlob(ReadOnlySpan1 rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(ReadOnlySpan1 data)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] data)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)