• <i id='itdD3'><tr id='itdD3'><dt id='itdD3'><q id='itdD3'><span id='itdD3'><b id='itdD3'><form id='itdD3'><ins id='itdD3'></ins><ul id='itdD3'></ul><sub id='itdD3'></sub></form><legend id='itdD3'></legend><bdo id='itdD3'><pre id='itdD3'><center id='itdD3'></center></pre></bdo></b><th id='itdD3'></th></span></q></dt></tr></i><div id='itdD3'><tfoot id='itdD3'></tfoot><dl id='itdD3'><fieldset id='itdD3'></fieldset></dl></div>

    <legend id='itdD3'><style id='itdD3'><dir id='itdD3'><q id='itdD3'></q></dir></style></legend>
  • <tfoot id='itdD3'></tfoot>

      • <bdo id='itdD3'></bdo><ul id='itdD3'></ul>
    1. <small id='itdD3'></small><noframes id='itdD3'>

      1. 引入 NETStandard.Library 依赖时的 System.* 引用问题

        System.* reference troubles when introducing NETStandard.Library dependency(引入 NETStandard.Library 依赖时的 System.* 引用问题)
          <tbody id='ejo2q'></tbody>

          <i id='ejo2q'><tr id='ejo2q'><dt id='ejo2q'><q id='ejo2q'><span id='ejo2q'><b id='ejo2q'><form id='ejo2q'><ins id='ejo2q'></ins><ul id='ejo2q'></ul><sub id='ejo2q'></sub></form><legend id='ejo2q'></legend><bdo id='ejo2q'><pre id='ejo2q'><center id='ejo2q'></center></pre></bdo></b><th id='ejo2q'></th></span></q></dt></tr></i><div id='ejo2q'><tfoot id='ejo2q'></tfoot><dl id='ejo2q'><fieldset id='ejo2q'></fieldset></dl></div>
            • <tfoot id='ejo2q'></tfoot>

            • <small id='ejo2q'></small><noframes id='ejo2q'>

                <bdo id='ejo2q'></bdo><ul id='ejo2q'></ul>

                <legend id='ejo2q'><style id='ejo2q'><dir id='ejo2q'><q id='ejo2q'></q></dir></style></legend>

                1. 本文介绍了引入 NETStandard.Library 依赖时的 System.* 引用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  在一个包含 52 个项目(全部为 net462)的大型解决方案中,我们的一些依赖项的最新版本现在仅针对 NET 标准构建.因此,它们依赖于 NuGet 包 NETStandard.Library,而后者又拖入了许多其他 4.3.x 版本的 System.* 包,这些包通常在 .NET Framework 中自己.

                  因此,一些项目从 packages 文件夹引用 System.* 库,而其他项目从 .NET Framework 引用 System.* 库.

                  这会导致众所周知的运行时问题 f.e.:

                  <块引用>

                  消息:System.IO.FileLoadException:无法加载文件或程序集System.Net.Http,版本=4.1.1.2,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配.(HRESULT 异常:0x80131040)

                  深入NETStandard.Library包的依赖关系,我们可以看到这些包中也存在同样的问题:

                  • System.Collections.*
                  • System.ComponentModel.*
                  • System.Console
                  • System.Globalization.*
                  • System.IO.*
                  • System.Linq.*
                  • System.Net.*
                  • System.ObjectModel
                  • System.Reflection.*
                  • System.Resources.ResourceManager
                  • System.Runtime.*
                  • System.Text.*
                  • System.Threading.*
                  • System.Xml.*

                  通常通过在其他项目中安装相同的包来解决这个问题,但我们在这里处理很多项目和很多包,我不想盲目地将所有这些依赖项添加到所有 52 个项目中.

                  这让我想知道是否有人知道一种简单的方法可以从这种情况中恢复并让所有项目从 NuGet 包文件夹中引用正确的包/DLL(如果他们当前使用 NET Framework 内部包).

                  可以在

                  1. 将包的相同版本(在您的情况下为 4.3.0)安装到 ConsoleApp1 项目.

                  2. 查看结果:

                  1. 重建解决方案.

                  完成.

                  <小时>

                  此外,将软件包版本整合到您的解决方案中是一种很好的做法.相反,您可能会在构建期间遇到版本冲突.或者,更糟糕的是,像 MethodNotFound 这样的运行时错误,因为绑定重定向到另一个版本的依赖项.

                  <小时>

                  System.Net.Http 问题的原因如下所述:Broken System.Net.Http 4.1.1-4.3.0 事后分析 在以后如何防止这种情况发生? 2.1

                  部分<块引用>

                  因此,我们确定了 2 个有问题的 OOB 包,它们不是平台本身的叶节点,而是依赖于平台 - System.Net.Http 和 System.IO.Compression.

                  这意味着相同的 System.Net.Http 库包含在 .NET Framework 和 OOB(带外)nuget 包中.一些 nuget 包可以引用它的 nuget 版本.这就是我一开始描述的问题.

                  因此,您不必修复对所有 System.* 库的引用.仅适用于这两个:System.Net.HttpSystem.IO.Compression.

                  In a large solution with 52 projects (all net462), the latest version of some of our dependencies are now only built for NET standard. Therefore they depend on the NuGet package NETStandard.Library which in turn drags in a lot of other 4.3.x version of System.* packages which are normally in the .NET Framework itself.

                  As a result, some projects reference System.* libraries from the packages folder, while others reference System.* libraries from the .NET Framework.

                  This causes the well-known runtime issue, f.e.:

                  Message: System.IO.FileLoadException : Could not load file or assembly 'System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

                  Digging into the dependencies of the NETStandard.Library packages, we can see that the same issue also exists in these packages:

                  • System.Collections.*
                  • System.ComponentModel.*
                  • System.Console
                  • System.Globalization.*
                  • System.IO.*
                  • System.Linq.*
                  • System.Net.*
                  • System.ObjectModel
                  • System.Reflection.*
                  • System.Resources.ResourceManager
                  • System.Runtime.*
                  • System.Text.*
                  • System.Threading.*
                  • System.Xml.*

                  Normally this is fixed by installing the same package in the other projects, but we're dealing with a lot of projects and a lot of packages here and I don't want to blindly add all of those dependencies to all 52 projects.

                  This made me wonder whether anyone knows of an easy way to recover from this situation and to make all projects reference the correct package/DLL from the NuGet packages folder if they currently use the NET Framework internal one.

                  A simple VS-solution for net462 and net471 demonstrating the problem can be found here

                  解决方案

                  In the default project template System.Net.Http is added to the project as a reference, not as a nuget package.

                  In both of your solutions (4.6.1 and 4.7.1):

                  • Project ClassLibrary has a dependency on System.Net.Http as a nuget package.

                  • Project ConsoleApp1 has a dependency on System.Net.Http as a simple reference from .NET Framework

                  So, the issue is not related to Target Framework version.

                  To fix the issue add the same version of System.Net.Http as a nuget package to all projects (where it is used).

                  1. Right-click the solution in Solution Explorer and choose Manage NuGet Packages for Solution...

                  2. Switch to Installed tab

                  3. Find System.Net.Http in the list, select it.

                  4. Check current state:

                  1. Install the same version of the package (4.3.0 in your case) to ConsoleApp1 project.

                  2. Check the result:

                  1. Rebuild the solution.

                  Done.


                  Also, it's good practice to have package versions consolidated in your solution. Instead, you could have version conflicts during build time. Or, which is worse, runtime error like MethodNotFound because of binding redirect to another version of the dependency.


                  The reason for the problem with System.Net.Http is described here: Broken System.Net.Http 4.1.1-4.3.0 post-mortem in section How to prevent such situation in future? 2.1

                  As a result we identified 2 problematic OOB packages, which are not leaf-nodes in the platform itself, and have dependency from the platform on them - System.Net.Http and System.IO.Compression.

                  It means that the same System.Net.Http library is shipped within .NET Framework and as OOB (out-of-band) nuget package. And some nuget packages could reference nuget version of it. And here it comes the problem that I described at the very beginning.

                  So, you don't have to fix references to all System.* libraries. Only for these two: System.Net.Http and System.IO.Compression.

                  这篇关于引入 NETStandard.Library 依赖时的 System.* 引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                  Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                  Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                  How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                  how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                  JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)

                  <small id='kyPIW'></small><noframes id='kyPIW'>

                    • <bdo id='kyPIW'></bdo><ul id='kyPIW'></ul>
                        <tbody id='kyPIW'></tbody>

                        <tfoot id='kyPIW'></tfoot>
                        1. <legend id='kyPIW'><style id='kyPIW'><dir id='kyPIW'><q id='kyPIW'></q></dir></style></legend>

                            <i id='kyPIW'><tr id='kyPIW'><dt id='kyPIW'><q id='kyPIW'><span id='kyPIW'><b id='kyPIW'><form id='kyPIW'><ins id='kyPIW'></ins><ul id='kyPIW'></ul><sub id='kyPIW'></sub></form><legend id='kyPIW'></legend><bdo id='kyPIW'><pre id='kyPIW'><center id='kyPIW'></center></pre></bdo></b><th id='kyPIW'></th></span></q></dt></tr></i><div id='kyPIW'><tfoot id='kyPIW'></tfoot><dl id='kyPIW'><fieldset id='kyPIW'></fieldset></dl></div>