简体   繁体   中英

Upgrade my Azure Function from .net Core 3.1 to .net Core 7.0. Error "'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstraction

I have an Azure Function which run on .net core 3.1, but when i change the .net version from 3.1 to 7 i got this error:-

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'

here is a screen shot:-

在此处输入图像描述

here is my csproj file:-

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.15.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
    <PackageReference Include="PnP.Core.Auth" Version="1.8.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Any advice on this please?

I have installed Install-Package Microsoft.Extensions.Configuration.Abstractions -Version 7.0.0 but this did not fix the issue either.

  1. .NET 3.1 is in-process and .NET 7 is Isolated Worker Process type.
  2. I can see your .csproj file code given in the question that you changed only .NET Framework and Azure Functions Version which is not complete configuration code for .NET 7 Isolated Process Azure Function and also you're missing few Function Worker package references in the .csproj file code.
  3. Basic/Default .NET 7 Isolated Azure Functions Project contains the below code in .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.2.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

在此处输入图像描述

  1. .NET 7 In-Process is not yet released and to convert from .NET 3.1 (In-Process Model) to .NET 7 (Isolated Worker Process), you need to write the .NET 7 Isolated Compatible NuGet Packages, code changes in the Function Code, program.cs file, etc.,

Refer to this MS Doc for Migration Steps & Checks of Azure Functions V3 to V4 and One of the my answers SO # 74428448 states the update of the supported available version in Azure Functions C#.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM