为什么Newtonsoft.Json如此容易出现程序集版本冲突? [英] Why is Newtonsoft.Json so prone to assembly version conflicts?

查看:492
本文介绍了为什么Newtonsoft.Json如此容易出现程序集版本冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,我们的项目中经常会出现程序集版本冲突,而90%的情况是底部是Newtonsoft.Json.有很多关于Newtonsoft.Json冲突的问题,例如臭名昭​​著的无法加载文件或程序集'Newtonsoft.Json,Version = 6.0.0.0".搜索"assembly'Newtonsoft. Json,Version = 6.0.0.0"提出了37个问题-许多问题都受到了高度评​​价.或此大约是4.5.0.0 .

I have noticed that we often get assembly version conflicts in our project, and 90% of the time it's Newtonsoft.Json at the bottom. There are many questions on SO specifically for Newtonsoft.Json conflicts - the infamous "Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0" for example. Searching for "assembly 'Newtonsoft.Json, Version=6.0.0.0" gives 37 questions - a lot of them highly upvoted. Or this one about 4.5.0.0.

是否有任何解释说明为什么这种情况经常发生在该库而不是其他库中?为什么它是如此一致的程序集版本冲突源?肯定比其他库更常见.

Is there any explanation why this happen so often with that library specifically instead of others, and why is it such a consistent source of assembly version conflicts? It definitely happens more often than with other libraries.

推荐答案

为什么Newtonsoft.Json如此容易出现程序集版本冲突?

Why is Newtonsoft.Json so prone to assembly version conflicts?

基本上,因为其他库应用程序代码通常将其用作下游依赖项.如果您拥有软件包A(在本例中为Netwonsoft.Json),并且您具有:

Basically, because it is commonly used as a downstream dependency by other libraries and application code. If you have package A (in this case, Netwonsoft.Json), and you have:

SomeApp
-> A

那一切都很好.但如果您有:

then all is great; but if you have:

SomeApp
-> A
-> SomeLib
   -> A

或:

SomeApp
-> SomeLib
   -> A
-> SomeOtherLib
   -> A

或:

SomeApp
-> A
-> SomeLib
   -> A
-> SomeOtherLib
   -> A

或:

SomeApp
-> A
-> SomeLib
   -> A
-> SomeOtherLib
   -> YetAnotherLib
      -> A
      -> MeTooLib
         -> A

然后A的所有引用版本都必须相同适当的程序集绑定重定向,以允许所需版本的lib 7以静默接受版本10,而不会引发绑定问题.当然,如果API在旧版本库使用的方法中在版本7和版本10之间不是二进制兼容的,那么您仍然完全不走运.

then all the referenced versions of A need to be the same, or suitable assembly-binding redirects need to be in place to allow a lib that expected version 7 to silently accept version 10 without throwing a binding issue. Of course, you're still completely out of luck if the API is not binary compatible between versions 7 and 10 in a method that the older library uses.

所以基本上:这是一个流行和重复使用的问题,也是 other 库的一个症状,该库未及时了解其下游依赖性. Json.NET认为它比其他库更多,因为它被使用比许多其他库更多,包括作为其他库的依赖.

So basically: this is a problem of popularity and re-use, and a symptom of other libraries not keeping up to date on their downstream dependencies. Json.NET sees this more than other libraries because it is used more than many other libraries, including as a dependency of other libraries.

请注意,NuGet会自动添加绑定重定向.

Note that NuGet automatically adds binding redirects.

这篇关于为什么Newtonsoft.Json如此容易出现程序集版本冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆