It was solved by adding: app.UseRouting(); in the program.cs class.
This error appeared to me when I had two controllers of the same name and actions. They were in the same solution but different projects.