Search code examples
c#blazorvisual-studio-2022

Getting error "Failed trusting the certificate" while running my Blazor App in Visual Studio 2022


I installed Visual Studio 2022 and created a Blazor web assembly project. When I started the application, Visual Studio 2022 prompted to trust the self signed certificate that ASP.NET Core has generated. Please refer below screen shot:

enter image description here

After I clicked "Yes" then it generated error "Failed trusting the certificate" as shown in below screen shot:

enter image description here

Please help me to fix the error. I have also tried following command but it did not fix my issue:

dotnet dev-certs https --trust

Note: Visual Studio 2019 is also installed on my machine i.e. currently I am having both VS2019 and VS2022 installed on my machine.


Solution

  • Finally I was able to fix the problem and I am mentioning the steps which fixed my problem. It can be beneficial for someone:

    Step 1: Open "Manage user certificates" by searching in Windows search bar and delete localhost certificate from "Personal -> Certificate": enter image description here

    Step 2: Now locate and delete localhost certificate from the "Trusted Root Certification Authorities -> Certificate": enter image description here

    Step 3: Open "Manage computer certificates" and delete localhost from both "Personal" and "Trusted Root Certification Authorities". It would be better if you take backup of your certificate before deleting it: enter image description here

    Step 4: Start Visual Studio in Administrative mode and run your application. Click Yes if prompted to trust the self-signed certificate: enter image description here

    Step 5: Now open "Manage user certificates" again and after selecting localhost click on Export: enter image description here

    Step 6: Click on Next button: enter image description here

    Step 7: Select "DER encoded binary X.509(.CER)" and click next: enter image description here

    Step 8: Save the file to Desktop with the name "localhost.cer" enter image description here

    Step 9: Now double click on the localhost.cer file that you just saved in Step 8 to install the certificate. enter image description here

    Step 10: Install the certificate for the "Local Machine": enter image description here

    Step 11: Select "Place all certificates in the following store" option and browse the certificate store by clicking on the browse button. Then select "Trusted Root Certification Authorities" enter image description here

    Step 12: Repeat Steps 9 to 11 but this time install it for "Current User" and install it in "Trusted Publishers" certificate store. enter image description here

    Step 13: Restart the Visual Studio and re-run your application and hope it will fix your problem.