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":

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

Step 3: Open "Manage computer certificates" and delete localhost from both "Personal" and "Trusted Root Certification Authorities":

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

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

Step 6: Click on Next button:

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

Step 8: Save the file to Desktop with the name "localhost.cer"

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

Step 10: Install the certificate for the "Local Machine":

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"

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

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