简体   繁体   中英

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

There is a recent principle on Nuget package parsing. For details, see how NuGet parses package dependencies. A Microsoft diagram is used to explain:

微软图片 This time you will choose the most recent package, which is the 2.0 version. 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.

<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.

The relationship route is [Package B 1.0.0] -> [Package 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.

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

Package A package generation version is 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? Is it because of the use of TargetFrameworks? I also hope that the big men will give pointers.

When I compare the *.deps.json file, I found something helpful. Here is the first scenario get the following json file: 最前一页

"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. Clearly understood.

After I make up the miss assembly version of the project, I got the right result.

第二

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM