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. 

Login to See the Rest of the 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?

© 2024 - ErnesTech - Privacy
E-Commerce Return Policy