如何解决无法加载文件或程序集 'Azure.Core'

How to resolve Could not load file or assembly 'Azure.Core'

任何人都可以解释为什么我们会收到诸如无法加载文件或程序集之类的错误。每当我在 azure sdk 中专门更新 nuget 引用时,我都会遇到这个错误,并且由于缺乏知识,我很难非常奇怪地修复它们。你能解释一下这个错误吗?我的意思是我可以消化这个错误,但我找不到真正的解决方案。

我已经明确决定我会理解这个错误并在这个平台上获得更多。如果你能一步一步地解释这个,那将增加我的知识和核心生产力。

我对此类错误的了解非常有限,我们需要在 web.config 文件中添加一些代码。

<bindingRedirect oldVersion="0.0.0.0-0.0.0.1" newVersion="0.0.0.1" />

但老实说,我不知道如何决定哪个版本需要用旧版本和新版本替换。我最近在我的项目中添加了 Azure.Identity nuget。

  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.5.0" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
 </ItemGroup>

例如,现在我一直在为这个错误而苦苦挣扎。

System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly 'Azure.Core, Version=1.19.0.0, Culture=neutral, 
PublicKeyToken=92742159e12e44c8' or one of its dependencies. The located assembly's 
manifest definition does not match the assembly reference. (Exception from HRESULT: 
0x80131040)
Source=Azure.Storage.Blobs
StackTrace:

我知道要更改哪里来解决这个错误,但不知道要更改什么。

我一直在阅读这篇url binding-redirects内容,了解了很多新知识。我已通过将以下 xml 添加到我的 we.config 文件中来修复此错误。

<dependentAssembly>
    <assemblyIdentity name="Azure.Core" publicKeyToken="92742159e12e44c8" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.20.0.0" newVersion="1.20.0.0" />
  </dependentAssembly>

为了处理这个错误这个门户真的很有帮助https://nuget.info/packages/Azure.Core/1.20.0

注: 有时 Nuget 版本不是汇编版本。所以要小心。