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

Azure Functions中Newtonsoft.Json版本冲突引发程序集加载异常求助

解决Azure Function中Newtonsoft.Json版本冲突问题

这个问题是典型的程序集版本冲突导致的——你的Azure Function依赖的Microsoft.NET.Sdk.Functions 1.0.8绑定了Newtonsoft.Json 9.0.1,但引用的类库需要更高版本的11.0.2,运行时就会找不到匹配的程序集。下面给你几个实用的解决思路:

方法一:配置程序集重定向

在Azure Function项目的根目录(和function.json同目录)创建app.config文件,添加重定向规则,让运行时把对11.0.0.0版本的请求导向实际存在的11.0.2版本:

<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-11.0.0.0" newVersion="11.0.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

记得先在你的Azure Function项目里安装Newtonsoft.Json 11.0.2的NuGet包,确保该程序集会被复制到输出目录。

方法二:升级Microsoft.NET.Sdk.Functions包

最彻底的办法是升级Microsoft.NET.Sdk.Functions到更高版本——比如1.0.30及以上的稳定版,已经默认依赖Newtonsoft.Json 11.0.2,直接和你的类库依赖版本对齐,从根源上避免冲突。

升级步骤很简单:

  • 在Visual Studio里右键项目→管理NuGet程序包
  • 找到Microsoft.NET.Sdk.Functions,选择更新到合适的稳定版本
  • 重新构建项目,确认所有依赖加载正常

方法三:强制复制指定版本的程序集

如果前两种方法不适用,可以手动确保Newtonsoft.Json 11.0.2的程序集被复制到输出目录:

  1. 先在Azure Function项目中安装Newtonsoft.Json 11.0.2 NuGet包
  2. 打开项目的.csproj文件,添加如下配置:
<ItemGroup>
  <Reference Include="Newtonsoft.Json, Version=11.0.2.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
    <HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
    <Private>True</Private>
  </Reference>
</ItemGroup>

注意根据你的项目目标框架,调整HintPath里的子目录(比如net461)。

小提醒:发布到Azure云环境时,记得勾选发布设置里的"包含所有项目文件",确保程序集能被正确上传。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:36:01