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

Azure Function部署后无法加载Newtonsoft.Json 13.0.0.0程序集求助

解决方案:Azure Function找不到Newtonsoft.Json 13.0.0.0异常

这个问题我之前帮不少开发者排查过,核心原因要么是强命名程序集的版本绑定冲突,要么是部署时正确的依赖文件没被带到Azure环境里,或者Azure Function运行时自带的组件和你的项目版本不兼容。给你几个针对性的解决步骤,按优先级尝试:

1. 添加版本绑定重定向配置

Azure Function运行时可能会尝试加载旧版本的Newtonsoft.Json(比如13.0.0.0),我们可以通过绑定重定向强制它使用你项目里的13.0.1版本:

针对.NET Framework项目

在项目根目录新建或修改web.config,添加以下配置:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

同时在项目的.csproj文件里确保开启自动生成绑定重定向:

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

针对.NET Core/.NET 6+项目

在项目根目录新建runtimeconfig.template.json文件,添加以下内容:

{
  "configProperties": {
    "assemblyBinding": {
      "dependentAssembly": [
        {
          "assemblyIdentity": {
            "name": "Newtonsoft.Json",
            "publicKeyToken": "30ad4fe6b2a6aeed",
            "culture": "neutral"
          },
          "bindingRedirect": {
            "oldVersion": "0.0.0.0-13.0.0.0",
            "newVersion": "13.0.1.0"
          }
        }
      ]
    }
  }
}

2. 确保依赖包被正确复制到部署包

有时候NuGet依赖不会被自动复制到输出目录,导致Azure上找不到正确的DLL。可以在.csproj里添加以下配置,强制所有锁定的依赖包都被复制:

<PropertyGroup>
  <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

3. 检查并对齐Azure Function运行时版本

Azure Function运行时可能自带了某个版本的Newtonsoft.Json,和你的项目版本冲突:

  • 登录Azure门户,进入你的Function App,在配置 > 常规设置里查看当前运行时版本(比如.NET 6/7/8)
  • 确保本地开发用的.NET版本和Azure上的完全一致,避免跨版本依赖冲突
  • 如果怀疑是运行时自带组件的问题,可以尝试切换到另一个兼容的运行时版本测试

4. 清理缓存并重新部署

旧的构建缓存或部署残留可能导致问题:

  • 本地删除项目的bin和obj目录,重新构建解决方案
  • 如果用CI/CD工具(比如Azure DevOps、GitHub Actions)部署,确保构建步骤是干净的,禁用缓存旧的依赖包
  • 手动重新发布到Azure,覆盖旧的部署包

5. 检查依赖树排除间接引用冲突

有可能是其他NuGet包间接引用了旧版本的Newtonsoft.Json,导致版本冲突:

  • 打开命令行,进入项目目录,运行dotnet list package查看完整依赖树
  • 找到所有引用Newtonsoft.Json的包,确认是否有强制指定旧版本的情况,必要时升级那些依赖包到兼容13.0.1的版本

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 18:30:59