So recently I had this error while I was adding authorization to a web API I have been building. If you're here I assume you've had something very similar.
It turns out, as the error suggests, I was using app.UseAuthorization() in the wrong location. I also found other posts on StackOverflow where people had the same problem. This is a very simple mistake to make as it can be rare to come across code that needs to be executed in a specific order, depending on what you build.
So how do we fix it?
The very easy fix for this is to move app.UseAuthorization() anywhere between app.UseRouting() and app.UseEndpoints() as in this example:
