The type or namespace name 'IHttpContextAccessor' could not be found (are you missing a using directive or an assembly reference)

Question: How do you resolve an error that says "An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately."

This error happened when I added 

builder.Services.AddRazorPages().AddRazorRuntimeCompilation();

Answer: I understand that adding a .AddRazorRuntimeCompilation() allow you to utilize "dotnet watch run" with Razor MVC changes. Without this ".AddRazorRuntimeCompilation()" the "dotnet watch run" does not work with Razor changes.

In order to resolve this error, just add an HttpContextAccessor() to your dependency injection pipeline and the error should go away.

I hope this helps you. 


Edit this Article
IHttpContextAccessor aspnet 6 ebook e-book .NET 6 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