Seems that everyone has a different answer for this. I also had this issue as well. There are many different things as you can tell that cause this issue. If you don't find any of these solutions helpful or have issues trying to go through all these different solutions, you can try running your application from the command line from the publish folder.
After publish, if you receive this error, go to your publish folder, and then open a command/terminal window, after that type dotnet .\YourStartupProject.dll
, you should receive an exception error, which should make fixing the issue easier.
For example, this is an error I received on trying on a new environment without setting up a SQL server, and of course, would receive this error.
Application startup exception: System.Exception: Could not resolve a service of type
'YourStartupProject.DataServices.DbContext.DbContext' for the parameter
'context' of method 'Configure' on type 'YourStartupProject.Startup'. --->
System.ArgumentNullException: Value cannot be null.
Parameter name: connectionString
Once you resolve your error, try it again, rinse, repeat.