Asp.Net Core 3.1 Dependency Injection Error Unable to resolve service for type 'Microsoft.AspNetCore.Http.HttpContext

Asp.Net Core 3.1 Dependency Injection Error Unable to resolve service for type 'Microsoft.AspNetCore.Http.HttpContext

Click to Watch Video

Error: Unable to resolve service for type 'Microsoft.AspNetCore.Http.HttpContext

Solution: There is a chance that you are trying to inject none Interface into a Class's Constructor. Remember, Dependency Injection works with Interfaces that have been registered with the Service Container in the Startup.cs Class file. When you try to inject HttpContext in the Constructor, the Error happens. For a solution to solve this problem see below:

  • Change HttpContext httpContext to IHttpContextAccessor contextAccessor in the Constructor of your Class, the error should be resolved.
  • Please leave a message below if this solution helped you, other users might want to see how you resolved the issue. Thank you. 

Edit this Article
Asp.net core .net core .net core tutorials Technology published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy