【问题标题】:Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies无法加载文件或程序集“Newtonsoft.Json,版本=12.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一
【发布时间】:2020-02-12 09:49:08
【问题描述】:

无法加载文件或程序集“Newtonsoft.Json,版本=12.0.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 我正在尝试在我的类库项目中使用 Newtonsoft.Json,但出现此错误。我到处搜索,但我在互联网上找到的解决方案都不适合我。有人有什么主意吗 ? .csproj 路径:

 <ItemGroup>
    <Reference Include="Microsoft.Crm.Sdk.Proxy">
      <HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.6.1.1\lib\net40\Microsoft.Crm.Sdk.Proxy.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="microsoft.identitymodel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.IdentityModel.7.0.0\lib\net35\microsoft.identitymodel.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Xrm.Sdk">
      <HintPath>..\packages\Microsoft.CrmSdk.CoreAssemblies.6.1.1\lib\net40\Microsoft.Xrm.Sdk.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="Microsoft.Xrm.Sdk.Workflow">
      <HintPath>..\packages\Microsoft.CrmSdk.Workflow.6.1.1\lib\net40\Microsoft.Xrm.Sdk.Workflow.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Activities" />
    <Reference Include="System.IdentityModel" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.Web.Extensions" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Xml.Linq" />
  </ItemGroup>

我项目中的 app.config 绑定:

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

我错过了什么吗? 我正在使用 .Net Framework 4

谢谢

【问题讨论】:

    标签: c# .net json.net


    【解决方案1】:

    无论是通过 Package Managere 控制台还是通过 NuGet GUI,我都会卸载/重新安装 Newtonsoft.Json。

    在包管理器控制台中执行:Update-Package –reinstall Newtonsoft.Json (请注意,如果您有多个项目,这将适用于整个解决方案)

    您可能需要在移除 app.config 中 Newtonsoft 的dependentAssembly 部分的同时执行此操作。

    也永远不要低估关闭和重新打开 Visual Studio 的威力。有时,您可以在自己周围寻找答案,以寻找刚刚消失的问题的答案,并且与 VS 缓存有关。

    【讨论】:

    • 我已经尝试了你的建议,但仍然没有运气,我仍然遇到同样的错误。
    • “找到的程序集的清单定义与程序集引用不匹配”表示您的版本不匹配。尝试回滚到版本 11(例如),然后升级回最新的 12.0.3。如果您的解决方案中有多个引用 NewtonSoft.Json 的项目,请确保合并版本。还要确保解决方案中的所有项目都具有正确的目标框架。
    【解决方案2】:

    清理这个烂摊子的可能性很小。 使用其中一种或几种:

    • 如之前回复Update-Package –reinstall Newtonsoft.Json所说的

    • 卸载 Newtonsoft.Json 及其上所有引用的包 + 手动删除 csproj 中的所有 binging 重定向和引用,然后重新安装包。

    • 重新安装解决方案Update-Package -reinstall的所有包。

    • 使用 .NET Core(最好的)

    希望,它会有所帮助。

    【讨论】:

      【解决方案3】:

      通过将引用直接链接到 .nuget\packages\newtonsoft.json\12.0.1\lib\net40\NewtonSoft.Json.dll 中的包内容解决了这个问题

      在包管理器中有一个引用确保包在那里。

      【讨论】:

        猜你喜欢
        • 2016-11-07
        • 2016-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-15
        • 2014-04-25
        • 1970-01-01
        • 2021-02-02
        相关资源
        最近更新 更多