我有一个DotNet 4.6.1应用程序与MVC和WebAPI。 MVC端具有GlobalConfiguration.Configuration,WebAPI依赖于Assembly1为什么我在DotNet的依赖地狱,我能做些什么来摆脱?
显然System.Web.Http中的GlobalConfiguration.Configuration对“Newtonsoft.Json,Version = 6.0.0.0”具有依赖性,而Assembly1具有依赖性在“Newtonsoft.Json”,版本= 7.0.1。
我把那些语录,正是因为它们是精确的依赖关系: 当我尝试对我的WebAPI运行ping我得到:
"Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies"
我的web.config通过的NuGet加入,创造了微软如此直到现在我还没有碰它,它是为我而建的。 web.config中的结构是:
<!--Personal Comment: See how configuration has no namespace-->
<configuration>
<runtime>
<!--Personal Comment: See how assemblyBinding DOES have namespace-->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<!--Left out all of the other dependentAssemblies for brevity-->
<dependentAssembly>
<!--Personal Comment: Take note the upper/lowercase of attributes-->
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral">
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0 newVersion="7.0.0.0" />
</assemblyIdentity>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
奇怪的是,如果我去的.csproj在VSCode和改变提及包括=“Newtonsoft.Json”,并删除版本= 7.0.0.0,等等......那么没有什么固定的。但是,如果我将版本= 7.0.0.0更改为版本= 6.0.0.0并将hintpath指向7.0.1,那么我的解决方案就可以运行!
这似乎是一个可怕的生活和编程方式,我不喜欢它,除非我必须处理它。根据我在网上阅读的每篇文章,每一个问题,每一个答案,他们都说“使用bindingRedirect”,他们以我尝试的方式使用它。我的假设是,bindingRedirect不适用于我的代码,我需要知道为什么,或者我可以以某种方式在引用中引用Newtonsoft.Json两次,并告诉编译器如果不是第三方项目使用7.0.0.0代码?
正在将所有内容升级到最新版本选项? – BOR4
不是。我在这种情况下的一个选项是完全删除MVC部分。 MVC被创建为引导代码并且未被使用。 但是 - 我不能说“这就是答案”的原因是因为我在保持dotnet 2.0代码库的同时多次遇到这个问题,我需要一劳永逸地解决这个问题,以便我知道当它再次发生时该怎么办。 – user3654055
你使用任何形式的源代码管理? – JuanR