Found conflicts between different versions of the same dependent assembly that could not be resolved
https://stackoverflow.com/questions/24772053/found-conflicts-between-different-versions-of-the-same-dependent-assembly-that-c
While the other responses say this, they don't make it explicit, so I will....
On VS2013.2, to actually trigger the emission of the cited information, you need to not read the message, which says:
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,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.
This is incorrect (or at least it was for some versions of Visual Studio - it seems to be OK on an up to date VS2015 Update 3 or later).
Instead turn it to Diagnostic (from Tools->Options->Project and Solutions->Build and Run, set MSBuild project build output verbosity), whereupon you'll see messages such as:
There was a conflict between "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=6.0.5.17707, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed".
- "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" was chosen because it was primary and "Newtonsoft.Json, Version=6.0.5.17707, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" was not.
Then
Ctrl-Alt-Oto go to Build output window- search for "was chosen" to find the drilldown.
..And yes, for those looking at the detail of the [diagnostic] message, it was news to this ignoramus that there's a convention in town whereby all 6.x versions are, internally Assembly Version 6.0.0.0, i.e. only the SemVer Major component goes into the Assembly Version :)
https://www.cnblogs.com/1996V/p/9037603.html#net18-5
为什么Newtonsoft.Json版本不一致?
而除了注意编译顺序外,我们还要注意程序集间的版本问题,版本间的错乱会导致程序的异常。
举个经典的例子:Newtonsoft.Json的版本警告,大多数人都知道通过版本重定向来解决这个问题,但很少有人会琢磨为什么会出现这个问题,找了一圈文章,没找到一个解释的。
比如:
A程序集引用了 C盘:\Newtonsoft.Json 6.0程序集
B程序集引用了 从Nuget下载下来的Newtonsoft.Json 10.0程序集
此时A引用B,就会报:发现同一依赖程序集的不同版本间存在无法解决的冲突 这一警告。
A:引用Newtonsoft.Json 6.0
Func()
{
var obj= Newtonsoft.Json.Obj;
B.JsonObj();
} B: 引用Newtonsoft.Json 10.0
JsonObj()
{
return Newtonsoft.Json.Obj;
}
A程序集中的Func方法调用了B程序集中的JsonObj方法,JsonObj方法又调用了Newtonsoft.Json 10.0程序集中的对象,那么当执行Func方法时程序就会异常,报System.IO.FileNotFoundException: 未能加载文件或程序集Newtonsoft.Json 10.0的错误。
这是为什么?
1.这是因为依赖顺序引起的。A引用了B,首先会先生成B,而B引用了 Newtonsoft.Json 10.0,那么VS就会将源引用文件(Newtonsoft.Json 10.0)复制到B程序集同一目录(bin/Debug)下,名为Newtonsoft.Json.dll文件,其内嵌程序集版本为10.0。
2.然后A引用了B,所以会将B程序集和B程序集的依赖项(Newtonsoft.Json.dll)给复制到A的程序集目录下,而A又引用了C盘的Newtonsoft.Json 6.0程序集文件,所以又将C:\Newtonsoft.Json.dll文件给复制到自己程序集目录下。因为两个Newtonsoft.Json.dll重名,所以直接覆盖了前者,那么只保留了Newtonsoft.Json 6.0。
3.当我们调用Func方法中的B.Convert()时候,CLR会搜索B程序集,找到后再调用 return Newtonsoft.Json.Obj 这行代码,而这行代码又用到了Newtonsoft.Json程序集,接下来CLR搜索Newtonsoft.Json.dll,文件名称满足,接下来CLR判断其标识,发现版本号是6.0,与B程序集清单里注册的10.0版本不符,故而才会报出异常:未能加载文件或程序集Newtonsoft.Json 10.0。
以上就是为何Newtonsoft.Json版本不一致会导致错误的原因,其也诠释了CLR搜索程序集的一个过程。
那么,如果我执意如此,有什么好的解决方法能让程序顺利执行呢?有,有2个方法。
第一种:通过bindingRedirect节点重定向,即当找到10.0的版本时,给定向到6.0版本
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<bindingRedirect oldVersion="10.0.0.0"
newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
注意:我看过有的文章里写的一个AppDomain只能加载一个相同的程序集,很多人都以为不能同时加载2个不同版本的程序集,实际上CLR是可以同时加载Newtonsoft.Json 6.0和Newtonsoft.Json 10.0的。
第二种:如何在编译时加载两个相同的程序集?对每个版本指定codeBase路径,然后分别放上不同版本的程序集,这样就可以加载两个相同的程序集。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<codeBase version="6.0.0.0"
href="D:\6.0\Newtonsoft.Json.dll" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<codeBase version="10.0.0.0"
href="D:\10.0\Newtonsoft.Json.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Found conflicts between different versions of the same dependent assembly that could not be resolved的更多相关文章
- GetBuiltProjectOutputRecursive error running Xamarin Forms iOS on Visual Studio
Seems like I get this weird problem while running Xamarin.iOS on Visual studio. This happened after ...
- System Error Codes
很明显,以下的文字来自微软MSDN 链接http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx M ...
- Exam E05-001 Information Storage and Management Version 3 Exam
Emc 考试 e05-001信息存储和管理版本3考试 [总问题:171] 哪种 emc 产品提供软件定义的存储基础架构的自动监视和报告? A. viprSrmB. 斯纳普内C. 阿瓦马尔D. 快速副总 ...
- winerror.h中的内容(可以查看last error对应)
/************************************************************************* ** winerror.h -- error co ...
- Windows Error Codes
http://www.briandunning.com/error-codes/?source=Windows Windows Error Codes List All Error Codes | S ...
- redmine 安装
现在redmine安装部署的方法有很多,有安装包,docker,虚拟机镜像,还可以在ubuntu,centos中添加安装源. 但是最好维护方法还是从源码去部署. 一. 目标环境: 1. Redmine ...
- .Net dependent configuration
error info: 解决方案:在.exe.config文件中配置Newtonsoft.Json所用版本 <runtime> <assemblyBinding xmlns=&quo ...
- [转]Porting to Oracle with Entity Framework NLog
本文转自:http://izzydev.net/.net/oracle/entityframework/2017/02/01/Porting-to-Oracle-with-Entity-Framewo ...
- 使用SVN更新项目后出现冲突说明
使用Update后出现多个文件,并且报错!! R.java.mine R.java.r21965 R.java.r23204 下面以自动生成R.java.mine,R.java.r21965, ...
随机推荐
- godoc工具使用
golang除了语言有一定的规范外,对于文档的生成也是非常不错的.仅仅要按go的格式来写的程序,都能够非常easy的生成文档. godoc命令介绍: http://golang.org/cmd/god ...
- 0x11 栈
这个不难吧,算是常识了..毕竟也是刷过USACO的人 对顶栈这东西前几天才遇到过,好像和在线求中位数那东西放一起了吧 单调栈倒是没什么...贴个代码算了.一开始有点蠢的每个位置算,后来发现出栈再算就行 ...
- java格式化时间到毫秒
转自:https://blog.csdn.net/iplayvs2008/article/details/41910835 java格式化时间到毫秒: SimpleDateFormat formatt ...
- Redis学习笔记(十一) 命令进阶:Connection(连接)
原文链接:http://doc.redisfans.com/connection/index.html auth password 有时候处于安全性考虑,我们可以使用密码来保护redis服务器,每次连 ...
- 在Ubuntu Server下搭建LAMP环境
1 LAMP的安装 LAMP通常是指Linux+Apache+MySQL+PHP组合形成的一套可以运行PHP程序的体系,并不是一个软件的名称.没有安装MySQL的服务器依然可以在其它条件完备的情况下运 ...
- Scrapy Architecture overview--官方文档
原文地址:https://doc.scrapy.org/en/latest/topics/architecture.html This document describes the architect ...
- 有关PHP数组
在PHP中,数组就是关键字和值的集合,我们可以使用array关键字创建: $arr=array[100,200,300,400,500]: //这是一个自定义数组,数组里面的值是自 ...
- APUE学习笔记7——进程间通信
1 管道 管道一般是一种半双工的进程间通信方式,只能够在具有公共祖先的进程之间使用,比如一个管道由一个进程创建,然后该进程调用fork,之后父.子进程就可以使用该管道. 管道是调用pipe函数创建的. ...
- 别让好想法埋没:如何进行APP开发?
经常和许多创业者讨论,发现很多人想法都不错,但是都不知道该如何实现,今天就如何引导大家走出第一步写一篇文章,很多人通常误会一件事情,认为程序员开发可以一步步把自己的想法拼接出来,我有一个功能点,就让程 ...
- Mac Dropbox 文件不显示同步图标 解决
前言 开始时关了这个功能,今天想打开发现怎么也恢复不了. 按照官方教程说的重装也无济于事.最后在官方BBS发现一篇帖子顺利解决了问题 解决方案 这哥们意思是说禁用了一个Finder的插件就好了(有意思 ...