In my case, the application was built using .NET 6.0, but my Visual Studio was set to use .NET 8.0, which caused the error. Later, I switched to IIS Express, which revealed the actual issue. After identifying it, I installed .NET 6.0, and that resolved the problem.