【问题标题】:JsonConvert Not working in Newtonsoft.Json Asp.net MVC C#JsonConvert 在 Newtonsoft.Json Asp.net MVC C# 中不起作用
【发布时间】:2021-07-29 01:13:28
【问题描述】:

我用的是Newtonsoft.Json.JsonConvert,但是报错如下:

“JsonConvert”类型存在于“Newtonsoft.Json”中, 版本=9.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed' 和 'Newtonsoft.Json,版本=12.0.0.0,文化=中性, PublicKeyToken=30ad4fe6b2a6aeed'

给出错误的图像

这是我做过的事情:

  1. 我已经构建了项目 Build -> Clean 然后 Build -> Rebuild
  2. 我右键单击项目并卸载项目,然后重新加载项目
  3. 我曾经删除重装过Newtonsoft.Json

以上我都做了,但是问题还没有解决怎么办? 我使用.net 4.6.1

在 web.config(运行时标签)中

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f"/>
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

【问题讨论】:

  • 我们需要更多地了解您正在使用的项目类型。基本上,您可能需要从版本 9 到版本 10 的 程序集绑定重定向...但是如果不了解有关您的应用程序的详细信息,很难比这更具体。 (如果您能够转移到 SDK 样式的项目,您可以在其中指定 NuGet 包作为引用,根据我的经验,这往往会使事情变得更简单。)
  • 版本 9 到版本 12 @JonSkeet
  • 可能是其他项目或组件参考 Newtonsoft
  • 您希望我在帖子中添加什么样的信息? @JonSkeet
  • 您可以先告诉我们您的申请。它是一个什么样的应用程序?您有哪些依赖项(以及哪些版本)?您使用的是哪个版本的 .NET?目前有哪些程序集绑定重定向到您?你能提供minimal reproducible example吗?

标签: c# json asp.net-mvc jsonconvert


【解决方案1】:

这是因为您的项目本身包含Newtonsoft JSON library with version Aone of the other project it reference also contains Newtonsoft JSON library version B

尝试为这两个项目引用一个版本。

你可以试试

  1. 删除较旧的,最好(从项目之一)
  2. 清理并重建整个解决方案
  3. 解决新的引用问题

【讨论】:

  • 我只有一个项目有这个库,没有其他项目
  • 尽管这描述了问题,但它未能解决它。
猜你喜欢
  • 2020-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-21
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
相关资源
最近更新 更多