Thursday, May 6, 2021

Clearing out old dev-certs from `dotnet dev-certs`

 If you are trying to run a dotnet app locally with HTTPS (normalization of which is a good idea for many reasons), you will need to trust the dev cert.  On Windows, this process was made particularly easy with the `dotnet dev-certs` tool.  Simply run `dotnet dev-certs https --trust` to install and trust a cert that your app can use to allow https forwarding.

If the process goes awry (usually because you've installed a bunch of different certs in the past), Chrome might still whine about the cert being bad.  Alternatively, you could get the following errors when you `dotnet run` your app:

Unable to start Kestrel.
System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.

You have a few options to solve this:

  1. Generate certs using the `dotnet dev-certs` tool:
    • Run `dotnet dev-certs https --clean` to clean up old certs
    • Run `dotnet dev-certs https` to generate a new one
    • Run `dotnet dev-certs https --trust` to trust the new cert
    • Build your app.  Et voila!
  2. If this does not work, I found a troubleshooting thread that ended up working for me.
    • Run `certmgr.msc`
    • Go to Personal --> Certificates
    • Delete all localhost certs
    • Run Step 1 to generate and then trust the cert again.
    • You should then be able to build and run your app and see it launch