Reputation: 679
I am creating this simple console application that will create my own certificate. Here's my code.
var fi = new FileInfo("certificate.cer");
if (!fi.Exists)
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = "makecert.exe";
startInfo.Arguments = "-sv SignRoot.pvk -cy authority -r sha1 -n \"CN=Certificate\" -ss my -sr localmachine certificate.cer";
Process.Start(startInfo);
}
X509Certificate.CreateFromCertFile("certificate.cer");
But why am i getting this on my last line of code?
CryptographicException was unhandled.
Message=The system cannot find the file specified.
Upvotes: 1
Views: 191
Reputation: 679
I resolved the situation by using a batch(.bat) file, because I find it easier. And let c# run the batch file when the program starts. Thanks for the help. :)
Upvotes: 0
Reputation: 35477
You need to wait for the makecert
process to exit before using the certificate.
Process
.Start(startInfo)
.WaitForExit();
Upvotes: 4