Here's another thing that worked for me. I use ASP.NET v8.0 but my project file from uses v6.0. Here's a step by step procedure on how to resolve the error:
- Open your .csproj file.
- Change the version from the version in the file to the version you are using.
- Save and close the file.
- Restart visual studio and the application. It will work for sure