You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Functions从.NET 6升级到.NET 8后运行时System.Linq加载失败

解决Azure Functions从.NET 6升级到.NET 8后System.Linq加载失败的问题

升级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>

解决方案

  • 更新Microsoft.NET.Sdk.Functions包版本
    版本4.2.0不兼容.NET 8,需升级到4.13.0及以上的兼容版本。修改.csproj中的对应引用:

    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.13.0" />
    
  • 清理重建项目
    执行命令清理缓存并重新构建,确保依赖正确加载:

    dotnet clean
    dotnet restore
    dotnet build
    
  • 确认Azure Functions Runtime兼容性

    • 本地开发:确保Azure Functions Core Tools是v4的最新版本,它已支持.NET 8。
    • 云端部署:确认Azure App Service的Functions Runtime已更新到支持.NET 8的v4版本(Azure默认已为v4 runtime提供.NET 8支持)。
  • 添加程序集绑定配置(可选,若上述步骤无效)
    在项目根目录创建runtimeconfig.template.json文件,内容如下:

    {
      "runtimeOptions": {
        "assemblyBinding": {
          "dependencies": [
            {
              "name": "System.Linq",
              "publicKeyToken": "b03f5f7f11d50a3a",
              "version": "8.0.0.0"
            }
          ]
        }
      }
    }
    

内容的提问来源于stack exchange,提问作者Faouzeya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 03:28:18