ASP.NET Core InvalidOperationException: Unable to resolve service for type ‘Microsoft.AspNetCore.Http.IHttpContextAccessor’ while attempting to activate

  • Avatar photo
  • 2023年10月21日

Trying to inject a service,

Then got the above error. The reason is HttpContextAccessor is no longer wired up by default, you have to register it manually.

Just add one line of code

or this line

solved the error.