简体   繁体   English

Nuget包引用导致“无法加载文件或程序集”?

[英]Nuget package references cause “Could not load file or assembly” ?

There is a recent principle on Nuget package parsing. Nuget包解析有一个最近的原则。 For details, see how NuGet parses package dependencies. 有关详细信息,请参阅NuGet如何解析包依赖项。 A Microsoft diagram is used to explain: Microsoft图表用于解释:

微软图片 This time you will choose the most recent package, which is the 2.0 version. 这次您将选择最新的软件包,即2.0版本。 no problem. 没问题。

One problem I encountered today is that one of my Nuget packages (called Package A current version 1.2.3) originally only supports the version of netstandard 2.0, which is defined in the csproj file. 我今天遇到的一个问题是我的一个Nuget包(称为Package A当前版本1.2.3)最初只支持netstandard 2.0的版本,它在csproj文件中定义。

<TargetFramework>netstandard2.0</TargetFramework>

I have another product, the ECS Nuget package (called Package B version 1.0.0), and Package B needs to reference Package A. 我有另一个产品,ECS Nuget包(称为包B版1.0.0),包B需要引用包A.

The relationship route is [Package B 1.0.0] -> [Package A 1.2.3] 关系路线是[包B 1.0.0] - > [包A 1.2.3]

At this time, the two packages in the program can be used normally. 此时,程序中的两个包可以正常使用。

Later, due to the support of the .net framework, I modified the original package A nuget package and changed it to the following. 后来,由于.net框架的支持,我修改了原始包A nuget包并将其更改为以下内容。

<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>

Package A package generation version is 1.3.2. 包的包生成版本是1.3.2。 At this time, I refer to the above two packages and find that the compilation is ok, but I am getting an error at runtime. 这时,我参考上面的两个包,发现编译没问题,但我在运行时遇到错误。

在此输入图像描述 I can solve the above problem by upgrading Package B, but why is this error? 我可以通过升级包B解决上述问题,但为什么会出现这个错误? Is it because of the use of TargetFrameworks? 是因为使用了TargetFrameworks吗? I also hope that the big men will give pointers. 我也希望大个子能指点一下。

When I compare the *.deps.json file, I found something helpful. 当我比较*.deps.json文件时,我发现了一些有用的东西。 Here is the first scenario get the following json file: 这是第一个获取以下json文件的场景: 最前一页

"aliyun-net-sdk-core/1.3.2": {
        "dependencies": {
          "Serilog": "2.5.0",
          "Serilog.Exceptions": "4.0.0",
          "Serilog.Sinks.File": "4.0.0"
        },
        "runtime": {
          "lib/netstandard2.0/aliyun-net-sdk-core.dll": {
            "assemblyVersion": "0.0.0.0",
            "fileVersion": "0.0.0.0"
          }
        }
      }

Because of the reference to version 1.3.2, however, the CLR can't find the DLL with Version 1.3.2 when loading the assembly, there is only assembly version 0.0.0.0, so the CLR looks for the 1.2.3 version referenced by the original project, but it is not found, so it reports an error. 但是,由于引用了1.3.2版本,CLR在加载程序集时找不到版本1.3.2的DLL,只有程序集版本0.0.0.0,所以CLR查找引用的1.2.3版本由原始项目,但没有找到,所以它报告错误。 Clearly understood. 清楚地了解。

After I make up the miss assembly version of the project, I got the right result. 在我编写项目的miss assembly版本后,我得到了正确的结果。

第二

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Elmah MySql Nuget包问题'无法加载文件或程序集' - Elmah MySql Nuget Package Issue 'Could not load file or assembly' 无法为 NET Standard 加载 NuGet 包的文件或程序集异常 NET 5/6 - could not load file or assembly exception NET 5/6 of NuGet package for NET Standard C# 无法加载文件或程序集:NuGet - C# Could not load file or assembly : NuGet 使用NHUnspell NuGet包时无法加载文件或程序集Hunspellx64.dll? - Could not load file or assembly Hunspellx64.dll while using NHUnspell NuGet package? 安装MVC论坛Nuget包后无法加载文件或程序集&#39;Ninject.Web&#39; - Could not load file or assembly 'Ninject.Web' after Install MVC Forum Nuget Package nuget 包重定向后无法加载文件或程序集“System.Runtime.InteropServices.RuntimeInformation” - Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation' after nuget package retargetting 无法加载文件或程序集 ICSharpCode.SharpZipLib... 当使用 nuGet 包 ExcelDataReader - Could not load file or assembly ICSharpCode.SharpZipLib… When using nuGet package ExcelDataReader '无法加载文件或程序集。 系统找不到指定的文件' - 打包后抛出 .NET 框架 NuGet package - 'Could not load file or assembly. The system cannot find the file specified' - thrown after packaging .NET Framework NuGet package 来自 NuGet package 的运行时异常引用类型:'无法加载文件或程序集'Foo'。 该系统找不到指定的文件。' - Runtime exception referencing type from a NuGet package: 'Could not load file or assembly 'Foo'. The system cannot find the file specified.' Nuget DLL地狱:无法加载文件或程序集System.Runtime - Nuget DLL Hell: Could not load file or assembly System.Runtime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM