I have a .p12 certificate file and I create my certificate like this:
var certificate = new X509Certificate2(certFileLocation, "mySecret", X509KeyStorageFlags.Exportable); When certFileLocation is on my desktop and I give the absolute path, the code works. But when I put the entire content of the .p12 file in a new file in my solution and set the Copy to Output Directory property of the file to "Copy if newer" I get a CryptographicException exception that says:
Cannot find the requested object
I also check every time whether the file is in place and it is. What is the difference between these two scenarios and why can't I read the file with the latter approach?
certFileLocation? Also when you get the exception are you running, debugging or testing (MSTest) the code?certFileLocationwill be the location of thep12file. This happens when I am debugging.