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 while running an Azure function dependency Injection project using the Visual Studio 2019 in my local machine.
Table of Contents
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.

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

Now it installed the Microsoft.Extensions.DependencyInjection.Abstractions assembly sucessfully.

Then when I tried running my Azure Function project, I got the error Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions.

The exact error message was
A host error has occurred during startup operation ‘e21f9c18-d1ee-4116-8397-67e3017cf895’.
[8/16/2020 7:32:44 AM] TsinfoEmployeCheck: 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.
Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions [Solved]
Now to fix this issue, I have followed the below steps
The first thing I have done is, I have uninstalled the Microsoft.Extensions.DependencyInjection.Abstractions assembly. Click on the Uninstall button to uninstall the Microsoft.Extensions.DependencyInjection.Abstractions assembly.

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

After I installed the Microsoft.Azure.Functions.Extensions package, I can able to run the Azure Functions project successfully without any issue.
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 tried running the project, I can able to run the project successfully with out any issue.

You may like to follow the below Articles
- Error While Redeploying The Azure Function System.Exception: Publishing failed
- CS1061 C# ‘HttpRequest’ does not contain a definition for ‘Content’ and no accessible extension method ‘Content’ accepting a first argument of type ‘HttpRequest’ could be found
- The specified module ‘ADSync’ was not loaded because no valid module file was found in any module directory error
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 the Microsoft.Extensions.DependencyInjection.Abstractions assembly to the project. Hope it will help to fix your issue !!!.
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.