Asp.Net Core 3.1 Error  The 'inject' directive expects an identifier

Problem: Severity Code Description Project File Line Suppression State
Error  The 'inject' directive expects an identifier. 

Answer: When developing in Asp.Net Core 3.1 and you try to inject a Service in the View, all of a sudden you see the Error  "The 'inject' directive expects an identifier". Below is the solution:

  • Look into your View specifically on the "@inject" directive, you will notice that one of the @inject Service does not have an instance name. 
    - @inject expects you to state a type of the object you are injecting into the View then define an instance. Look at it like instantiating a new object but in this case, you're only creating an instance that you will later use to access the functions defined in the Mock Repository or an Interface.

    @inject UserManager<YourService> //This is the wrong way to inject a dependency
    @inject IViewLocalizer localizer //This is the correct way to inject a dependency?

Edit this Article
.net core core mvc core tutorial 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