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. 


Please Login to see the rest of the answer

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?

Write an Article
If you log in, you will be notified when someone leaves a comment.

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


© 2022 - ErnesTech - Privacy