I have a problem where during runtime, my application get the exception:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Azure.Core, Version=1.40.0.0, Culture=neutral,
PublicKeyToken=92742159e12e44c8' or one of its dependencies.
The system cannot find the file specified.'
The funny thing is, that the nuget package I have installed is Version 1.41.0.0
.
I cannot seem to find anywhere that it reference to version 1.40.0.0
.
I also checked my output folder to see the version of Azure.Core
and that is correctly 1.41.0.0
I can see in the app.config that I have a bindingRedirect:
<dependentAssembly>
<assemblyIdentity name="Azure.Core" publicKeyToken="92742159e12e44c8" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.41.0.0" newVersion="1.41.0.0" />
</dependentAssembly>
I am scratching my head as to why this is happening?
EDIT:
After setting my MSBuild to Diagnostic
, it reads out the following:
Unified primary reference "Azure.Core, Version=1.41.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8". (TaskId:21)
1> Using this version instead of original version "1.40.0.0" in "C:\Users\user\.nuget\packages\azure.identity\1.12.0\lib\netstandard2.0\Azure.Identity.dll" because AutoUnify is 'true'. (TaskId:21)
1> Using this version instead of original version "1.37.0.0" in "C:\Users\user\.nuget\packages\azure.security.keyvault.secrets\4.6.0\lib\netstandard2.0\Azure.Security.KeyVault.Secrets.dll" because AutoUnify is 'true'. (TaskId:21)
1> Resolved file path is "C:\Users\user\.nuget\packages\azure.core\1.41.0\lib\net472\Azure.Core.dll". (TaskId:21)
1> Reference found at search path location "{RawFileName}". (TaskId:21)
1> Found related file "C:\Users\user\.nuget\packages\azure.core\1.41.0\lib\net472\Azure.Core.xml". (TaskId:21)
1> This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true". (TaskId:21)
Based on your comment it looks like you have an issue with transitive packages. The packages Azure.Identity and Azure.Security.KeyVault.Secrets both need the Azore.Core package. As I do not have a full overview of your project setup, the following solutions might or might not work, dependent on your project structure.
1.) Remove your reference to Azure.Core
As the other assemblies already refer Azure.Core, Azure.Core should still be referable for you, even when you do not have a direct dependency to it. That might solve the issue already, but as both packages (Azure.Identity and Azure.Security.KeyVault.Secrets) refer Azure.Core, they both might also refer two different versions. In this case, you need to change the versions of those packages until you find matching Azure.Core versions.
2.) Update your direct Azure.Core reference to a corresponding version
In case you still need/want the direct reference, make sure your referenced version fits to the version the other packages refer to. For example:
Azure.Identity V1.12.0 -> Requires Azure.Core >= V1.25.0
Azure.Security.KeyVault.Secrets V4.4.0 -> Requires Azure.Core >= V1.25.0
Direct reference Azure.Core V1.20.0 -> Upgrade to V1.25.0
(those are really just examples, in reality its more likely that the packages often require different versions, so this is really a happy case)