Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions

In this Azure tutorial, we will discuss how to fix the error, Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions. This error I got this while running an Azure function dependency Injection project using Visual Studio 2019 on my local machine.

Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions

I have an Azure Function project where I am trying to implement the Dependency Injection as well. I have referred to Microsoft.Extensions.DependencyInjection.Abstractions assembly to the project by installing that from the Nuget Package following the below steps

Right-click on the Project —> Manage Nuget Packages and then search for Microsoft.Extensions.DependencyInjection.Abstractions and then click on the Install button.

Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions

Then I clicked on the I Accept button from the below pop-up to accept the License acceptance.

could not load file or assembly 'microsoft.extensions.logging.abstractions, version=8.0.0.0, culture=neutral, publickeytoken=adb9793829ddae60'. the system cannot find the file specified.

Now it has installed Microsoft.Extensions.DependencyInjection.Abstractions assembly successfully.

system.private.corelib: could not load file or assembly 'microsoft.extensions.logging.abstractions

Then when I tried running my Azure Function project, I got this error.

could not load file or assembly 'microsoft.extensions.configuration.abstractions, version=8.0.0.0

The exact error message was

A host error has occurred during startup operation ‘e21f9c18-d1ee-4116-8397-67e3017cf895’. Could not load file or assembly ‘Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.7.0, Culture=neutral, PublicKeyToken=adb9793829ddae60’. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.

Solution

Now to fix this issue, I have followed the below steps

1. The first thing I did was uninstall Microsoft.Extensions.DependencyInjection.Abstractions assembly. Click on the Uninstall button to uninstall Microsoft.Extensions.DependencyInjection.Abstractions assembly.

could not load file or assembly 'microsoft.extensions.configuration.abstractions, version=8.0.0.0, culture=neutral, publickeytoken=adb9793829ddae60'. the system cannot find the file specified.

2. Install the Microsoft.Azure.Functions.Extensions assembly instead of the Microsoft.Extensions.DependencyInjection.Abstractions assembly. Search for the Microsoft.Azure.Functions.Extensions assembly and then click on the install button to install it. The Microsoft.Azure.Functions.Extensions assembly also references the Microsoft.Extensions.DependencyInjection. Abstractions package.

could not load file or assembly 'microsoft.extensions.configuration.abstractions

3. After I installed the Microsoft Azure Functions Extensions package, I was able to run the Azure Functions project successfully without any issues.

Here is my Azure function code

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Linq;

namespace TsinfoEmployeCheck
{
    public  class Function2
    {
        private readonly IEmployeeService employeeService;
        public Function2(IEmployeeService employeeService)
        {
            this.employeeService = employeeService;
        }
        [FunctionName("TsinfoEmployeCheck
")]
        public  async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

           
            string empemail123 = req.Query["EmailID"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            empemail123 = empemail123 ?? data?.empemail123;

           
        string response = employeeService.EmployeeEmail(empemail123);
                return response == "Valid EmailID"
                ? (ActionResult)new OkObjectResult($"TSINFO Valid Employee belongs to TSINFO")
                : new BadRequestObjectResult("Invalid Employee.Not belongs to the TSINFO");

          
        }
    }
}

Now, when I try running the project, I am able to run it successfully without any issues.

the 'function1' function is in error: could not load file or assembly 'microsoft.extensions.logging.abstractions, version=7.0.0.0, culture=neutral, publickeytoken=adb9793829ddae60'. the system cannot find the file specified.

Conclusion

Well, in this article, we discussed how to fix the error “Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions” that I got while trying to run my Azure Function project after referring to the Microsoft.Extensions.DependencyInjection.Abstractions assembly to the project. I hope it will help to fix your issue!!!

1 thought on “Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions”

  1. I am receiving Could not load runtime error for the same assembly but with version 5.0.0.0.
    Error:
    A host error has occurred during startup operation…
    Could not load file or assembly ‘Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60’. The system cannot find the file specified.

    I followed your suggestion of uninstalling Microsoft.Extensions.DependencyInjection.Abstractions and installing Microsoft.Azure.Functions.Extensions. However my error remains. Looking at the referenced DLLs in ILSpy, I found Microsoft.Azure.Functions.Extensions actually references an older version of Microsoft.Extensions.DependencyInjection.Abstractions, version 2.1.0.0.

Comments are closed.

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!