Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure function V3 could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0 with EF core 5.0-rc1

Case

We are creating azure function v3 with .netcore 3.1. Using EF core 5.0-rc1 and Depdency Injection

1) DependecyInjection

[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
namespace xxxxx
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var services = builder.Services;
            var configBuilder = new ConfigurationBuilder()
                .SetBasePath(Environment.CurrentDirectory)
                .AddJsonFile("local.settings.json", true, reloadOnChange: true)
                .AddEnvironmentVariables() ;
            ConfigureServices(services);
            ConfigureAppSettings(services, configBuilder.Build());
            ConfigureLogging(services, configBuilder.Build());
        }
    }
}

2) EF core 5.0 rc-1

https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-efcore-5-0-rc1/

Error

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.

image

Packages

Following are the packages referenced

image

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-rc.1.20451.14" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
    <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Troubleshooting

commenting the following line in startup.cs (Dependency injection) solves the problem

[assembly: FunctionsStartup(typeof(xxxxx.Startup))]
like image 703
Rupesh Avatar asked Sep 19 '20 19:09

Rupesh


3 Answers

The Microsoft.Azure.Functions.Extensions depends on .net standard 2.0.

enter image description here

While the Entity Framework Core 5.0 RC1 will not run on .Net standard 2.0 platforms, it requires .net standard 2.1. So it could not find the Microsoft.Azure.Functions.Extensions.

enter image description here

For more details, you could refer to this article.

like image 69
Joey Cai Avatar answered Oct 17 '22 15:10

Joey Cai


If you are using .NET core 3.1 or below that. Downgrade the NuGet packages of Microsoft.Extensions.DependencyInjection and Microsoft.Extensions.DependencyInjection.Abstractions to 3.x.x.

like image 6
Nivedha Lakshmanan Avatar answered Oct 17 '22 15:10

Nivedha Lakshmanan


It's not supported in Azure Function v3, yet. https://github.com/Azure/azure-functions-vs-build-sdk/issues/472

But, if you want to test it locally, I was able to run updating the DLL's in the Azure Function Core Tools directory: C:\Program Files\Microsoft\Azure Functions Core Tools

I needed to replace/update these Dll's to use EF5 with my functions: Dll's list

Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Options.dll
Microsoft.Extensions.Primitives.dll
like image 2
Thiago Silva Avatar answered Oct 17 '22 15:10

Thiago Silva