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

求助:类型‘SecurityTokenDescriptor’存在两个程序集冲突问题

解决类型‘SecurityTokenDescriptor’的程序集冲突问题

排查并移除间接引用

  • 打开NuGet包管理器,检查所有已安装的包,找出间接引入Microsoft.IdentityModel(v3.5.0.0)的依赖包,尝试更新该依赖包到兼容新版本的版本,或替换为不依赖旧程序集的替代包。
  • 直接编辑项目文件(.csproj),搜索<Reference Include="Microsoft.IdentityModel",如果存在该引用节点,直接删除。

添加程序集绑定重定向

若无法彻底移除旧程序集的引用,在项目的App.config或Web.config中添加绑定重定向规则,强制使用Microsoft.IdentityModel.Tokens的版本:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.IdentityModel" 
                          publicKeyToken="31bf3856ad364e35" 
                          culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" 
                         newVersion="6.26.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

注意:publicKeyToken需与你项目中Microsoft.IdentityModel.Tokens程序集的公钥令牌一致,可通过查看程序集属性确认。

清理项目缓存

  • 删除项目目录下的bin和obj文件夹,重新生成解决方案,清除残留的旧程序集文件。
  • 清理NuGet本地缓存,避免旧版本包的干扰。

显式指定类型命名空间

在代码中使用SecurityTokenDescriptor时,直接指定完整命名空间,消除编译器的歧义:

var tokenDescriptor = new Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor();

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 12:10:23