Unable to resolve class library references in dotnet core 5 app

Muhammad Nabeel Iqbal 0 Reputation points

I have class library and i have used that class library as a project reference in my dotnet core 5 webapi project.

And i have used it in the controller like this

But when i hit this controller from post man i get error saying:

Im not sure what i am doing wrong.

A set of technologies in the .NET Framework for building web applications and XML web services.
4,385 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. AgaveJoe 27,656 Reputation points

    The original error message means you did not register service with the IoC container in the startup.cs file.

    services.AddScoped<IAccountService, AccountService>();

    Please read the official documentation.


    Also, please post code on the forum using the "Code Sample" button rather than a screenshot

    1 person found this answer helpful.

  2. JasonPan - MSFT 4,811 Reputation points Microsoft Vendor

    Hi @Muhammad Nabeel Iqbal

    Your VirtualAssistantsController should be changed like below. Then the VirtualAssistantsController will be successfully initialized and the services can be injected into the Controller.

    public class VirtualAssistantsController : Controller  
        private readonly ILogger<VirtualAssistantsController> _logger;  
        private readonly WebUserService _webUserService;  
        private readonly AllControllerServices _services;  
        private readonly  AccountService _accountService;  
        public HomeController(ILogger<VirtualAssistantsController> logger, WebUserService webUserService, AllControllerServices services, AccountService accountService)  
            _logger = logger;  
            _webUserService = webUserService;  
            _services = services;  
            _accountService = accountService;  

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    0 comments No comments

  3. Muhammad Nabeel Iqbal 0 Reputation points

    Hello Jason thanks for writing back.
    I have a controller base class on which WebUserService webUserService, AllControllerServices services are registered.
    this is what library class looks like
    and this is how basecontoller looks like

    0 comments No comments