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

未引用Microsoft.IdentityModel.Tokens 5.3.0.0却遇加载异常,求解决方案

解决未直接引用却出现Microsoft.IdentityModel.Tokens 5.3.0.0加载异常的问题

你的解决方案虽未直接引用Microsoft.IdentityModel.Tokens 5.3.0.0版本,但出现程序集加载不匹配的异常,这通常是间接依赖导致的——某个已引用的NuGet包依赖了这个特定版本,而本地加载的版本和它要求的不一致。可以按以下步骤处理:

  • 排查间接依赖:在Package Manager Console中执行命令Get-Package -ProjectName MyMVCApp -IncludeTransitive,查看所有间接依赖的包,定位到哪个包依赖了5.3.0.0版本的Microsoft.IdentityModel.Tokens。
  • 添加程序集绑定重定向:若不想调整依赖版本,可在项目的web.config(或app.config)中添加配置,强制应用加载你实际安装的版本。示例配置如下:
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.IdentityModel.Tokens" publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-5.3.0.0" newVersion="你实际安装的版本号" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>
  • 调整相关依赖包:如果绑定重定向无效,找到依赖5.3.0.0的目标包,尝试升级或降级该包到兼容当前Microsoft.IdentityModel.Tokens版本的版本;也可直接安装5.3.0.0版本的Microsoft.IdentityModel.Tokens,满足间接依赖要求。
  • 清理重建解决方案:执行Clean Solution后再Rebuild Solution,清除旧程序集缓存,确保加载正确版本。

错误信息(中文翻译):
System.IO.FileLoadException
HResult=0x80131040
消息:无法加载文件或程序集“Microsoft.IdentityModel.Tokens, Version=5.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或其依赖项之一。找到的程序集清单定义与程序集引用不匹配。(异常来自 HRESULT:0x80131040)
来源:MyMVCApp

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 00:27:11