将我的 Azure 函数升级到 .net8 失败,并出现错误 Could not load file or assembly 'System.Linq, Version=8.0.0.0

Upgrading my Azure function to .net8 fails with the error Could not load file or assembly 'System.Linq, Version=8.0.0.0

提问人:Faouzeya 提问时间:11/17/2023 更新时间:11/18/2023 访问量:52

问:

将我的 Azure Functions 应用从 .NET 6 升级到 .NET 8 时,生成成功,但在运行时出现以下错误System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Linq, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'

这是我的.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
    <PackageReference Include="NPOI" Version="2.6.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>

如何修复此错误?

C# Azure-Functions Net-8.0

评论

0赞 Martin Costello 11/17/2023
你使用的是实际支持 .NET 8 的 Azure Functions 变体吗?techcommunity.microsoft.com/t5/apps-on-azure-blog/......
0赞 Piotr Nawrot 11/17/2023
正如@MartinCostello指出的,目前仅支持进程外。它设置在: - OutOfProcess = “FUNCTIONS_WORKER_RUNTIME”: “dotnet-isolated” - InProcess = “FUNCTIONS_WORKER_RUNTIME”: “dotnet”settings.json

答:

0赞 Sergei Avraimov 11/18/2023 #1

需要适用于 .NET 8 的其他包,因为需要使用独立模型。

使用新版本的最简单方法是在 Visual Studio 2022 v17.8 或更高版本中创建一个新项目,然后将代码移动到该位置。

对于进程内模型,它们将在 2024 年更新到 .NET 8

评论

0赞 David G 11/29/2023
根据 techcommunity.microsoft.com/t5/apps-on-azure-blog/...,无论如何,在 .NET 8 之后,对进程内模型的支持都将被取消,因此现在迁移到独立模型可能是一个明智的前进方向。