Search code examples
c#ssl.net-corewindows-10dotnet-cli

After running dev-certs https --trust, dotnet run complains that the default developer certificate could not be found


We read this documentation.

We ran the following in PowerShell:

dotnet dev-certs https --clean
dotnet dev-certs https --trust
dotnet dev-certs https --check # none found :-(

Then we opened a new PowerShell session and ran this:

dotnet dev-certs https --check # still none found :-(
dotnet run

This is the error message.

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.

Here is the output of dotnet --info

.NET SDK (reflecting any global.json):
 Version:   5.0.302
 Commit:    c005824e35

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.302\

Host (useful for support):
  Version: 5.0.8
  Commit:  35964c9215

How can we point dotnet run to the certificate that we created with dotnet dev-certs https --trust?


Solution

  • Based on https://stackoverflow.com/a/65266499/1108891, we manually deleted all certificates that localhost issued and then repeated our steps. This is how we deleted all localhost issued certs.

    Get-ChildItem -Path Cert:\CurrentUser -Recurse `
    | Where { $_.PSISContainer -eq $false } `
    | Where { $_.Issuer -match 'localhost' } `
    | Remove-Item -Whatif;
    
     Get-ChildItem -Path Cert:\LocalMachine -Recurse `
    | Where { $_.PSISContainer -eq $false } `
    | Where { $_.Issuer -match 'localhost' } `
    | Remove-Item -Whatif 
    

    The -Whatif is there to avoid copy/paste from clobbering an unwitting reader's certificate store. We removed it when we ran this step.