I have a asp.net core app that I started building through visual studio and normally it works fine when I press F5 or press the debug button in visual studio.
Howeve
Error occurred because value of ASPNETCORE_ENVIRONMENT variable is different. In case of Visual Studio it was set to Development
and in case of dotnet cli (as you can see in screenshot in question), it was Production
.
To set ASPNETCORE_ENVIRONMENT variable using command line, use below command -
setx ASPNETCORE_ENVIRONMENT "Development"
For more information on how to set hosting environment, please refer this article.