【问题标题】:'Newtonsoft.Json...' exists in both 'Blend\Newtonsoft.Json.dll' and 'Solution\packages\...\'Newtonsoft.Json...' 存在于 'Blend\Newtonsoft.Json.dll' 和 'Solution\packages\...\
【发布时间】:2014-03-06 08:42:51
【问题描述】:

我无法在 Visual Studio 2013 中构建解决方案。

这只是在我将 JSON.NET 包更新到 6.0.1 之后发生的。在此之前,它就像一个魅力。

有什么想法吗?

PS:这可能与 OWIN 有关。我认为它也引用了 JSON.NET,也许是动态的?

完全错误

Error   11  The type 'Newtonsoft.Json.Linq.JObject' exists in both 
'c:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll' and
'c:\Users\Me\Desktop\Solutions\[Project]\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll'
C:\Users\Me\Desktop\Solutions\[Project]\TrendPin\App_Start\Startup.Auth.cs  48  21  [Project]

我的 Web.Config 中有这个

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>

我的 .csproj 中有这个

<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>

构建输出

1>------ Build started: Project: [Project].Backend, Configuration: Debug Any CPU ------
1>  All packages listed in packages.config are already installed.
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
1>  [Project].Backend -> C:\Users\Me\Desktop\Solutions\[Project]\[Project].Backend\bin\Debug\[Project].Backend.dll
2>------ Build started: Project: [Project].Data, Configuration: Debug Any CPU ------
2>  All packages listed in packages.config are already installed.
2>  [Project].Data -> C:\Users\Me\Desktop\Solutions\[Project]\[Project].Data\bin\Debug\[Project].Data.dll
3>------ Build started: Project: [Project], Configuration: Debug Any CPU ------
3>  All packages listed in packages.config are already installed.
3>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3243: No way to resolve conflict between "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.
3>  Consider app.config remapping of assembly "Newtonsoft.Json, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" from Version "4.5.0.0" [C:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll] to Version "6.0.0.0" [C:\Users\Me\Desktop\Solutions\[Project]\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll] to solve conflict and get rid of warning.
3>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3247: Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /><bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /></dependentAssembly></assemblyBinding>
3>C:\Users\Me\Desktop\Solutions\[Project]\[Project]\App_Start\Startup.Auth.cs(48,21,48,28): error CS0433: The type 'Newtonsoft.Json.Linq.JObject' exists in both 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll' and 'c:\Users\Me\Desktop\Solutions\[Project]\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll'
4>------ Skipped Build: Project: [Project].Tests, Configuration: Debug Any CPU ------
4>Project not selected to build for this solution configuration 
========== Build: 2 succeeded, 1 failed, 0 up-to-date, 1 skipped ==========

【问题讨论】:

  • 转到引用,删除旧的并手动将新的添加到包文件夹中的正确 dll 中。设置复制=真。您必须小心更新内容。看起来您引用了两个版本。您可能只需要删除一个
  • OWIN 实际上引用了旧版本,据我所知。我删除了 OWIN,它起作用了。但我希望他们一起工作。 (我也更新了问题)
  • 您可以反映owin 并查看它在参考中寻找什么。如果它寻找特定版本,你有麻烦,但如果没有,只需将你想要的版本与 owin 一起放入 bin 并希望签名匹配。还要记住,还有 GAC。所以,你还有实验的空间
  • 请把它写成答案,我会接受。先生,你解释得很好。
  • 这篇文章中接受的答案为我解决了这个问题:stackoverflow.com/questions/21791597/…

标签: c# asp.net .net visual-studio json.net


【解决方案1】:

在您的 csproj 文件中,您会注意到 Newtonsoft.Json 有 2 个条目。删除以下条目:

<Reference Include="Newtonsoft.Json">
    <HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>

【讨论】:

  • 我只有 1 个 Newtonsoft.Json 条目,不幸的是您建议删除它。那么,您能否在此处粘贴其他参考条目?谢谢。
  • 这可能不适用于VS扩展项目,见related discussion
  • 你摇滚!谢谢你。
  • 当您的项目甚至没有任何 newtonsoft 引用时,这种情况经常发生。不知何故,VS 似乎能够扫描程序集引用中的依赖关系,并尝试解决其中的一些问题。我们仍在努力寻找一种解决方案,让它不从(在我们的例子中)Visual Studio 混合文件夹中复制 newtonsoft dll。
  • 这是公牛。现在它可以编译了,但是你得到一个无效的 newtonsoft json 版本的运行时错误......
【解决方案2】:

您可以反映owin 并查看它在参考中寻找什么。如果它寻找特定的版本,你有麻烦,但如果没有,只需将您想要的版本与owin一起放入应用程序bin并希望签名匹配。还要记住,还有 GAC。所以,你有实验的空间

【讨论】:

  • 不,不应该,因为 OP 在 proj 文件中从来没有重复条目
  • 注意!!! 在对此投票之前,请阅读有问题的 cmets,您会发现删除一个引用是我的第一个建议之一。现在,另一个答案不适用于所有情况。 OP的问题与该答案中解决的问题不同。没有 2 个条目可以删除。 Op 需要在应用适当的解决方案之前找到问题的来源。显然,查看程序集有助于找到不兼容的来源。谢谢。
【解决方案3】:

合并后我遇到了几乎相同的问题。结果是合并在 csproj 文件中留下了对 Newtonsoft.Json 的两个引用。项目中有DLL,NuGet包管理器中只有一个版本,但是csproj引用了Newtonsoft.Jason 5.0.6和5.0.8

我在 notepad++ 中编辑了 csproj 并删除了有问题的引用,等等。它解决了构建错误

【讨论】:

    猜你喜欢
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多