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

新建消耗层Azure Function App部署后无法加载System.Net.Primitives程序集

解决Azure消耗层Function App部署后System.Net.Primitives加载失败问题

核心排查方向及解决方案

1. 对齐本地与Azure的.NET运行时版本

  • 打开Azure门户的Function App,进入配置>常规设置,确认运行时堆栈的.NET版本与本地Visual Studio项目的目标框架完全一致(比如本地用.NET 8,Azure也要设置为.NET 8)。
  • 若版本不匹配,修改后重启Function App。

2. 调整项目依赖配置

  • 打开项目的.csproj文件,检查是否存在对System.Net.Primitives的手动引用,若有直接移除(.NET Core/.NET 5+已将该组件内置到SDK,无需手动引入)。
  • 确保<TargetFramework>标签内容与Azure运行时版本匹配,例如:
    <TargetFramework>net8.0</TargetFramework>
    
  • 若仍有问题,添加绑定重定向配置:在项目根目录创建app.config文件,写入以下内容:
    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Net.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    

3. 清理并重新部署

  • 本地操作:在Visual Studio中执行生成>清理解决方案,再重新生成项目。
  • Azure端清理:进入Function App的高级工具>Kudu>调试控制台>CMD,进入site/wwwroot目录删除所有文件,再重新部署。
  • 发布时勾选删除目标中的额外文件选项,避免旧文件残留干扰。

4. 检查Function App扩展与配置

  • 进入门户的配置>功能扩展,确保所有扩展为最新兼容版本。
  • 确认应用设置中的FUNCTIONS_EXTENSION_VERSION字段值与项目匹配:.NET 6+对应~4,.NET Core 3.1对应~3。

项目配置检查要点

以基础HTTP触发函数为例,.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" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

内容的提问来源于stack exchange,提问作者User-243d

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 10:34:57