C# nuget package dependency consolidation fails when running app as azure webjob


The exception when running as the console application as Azure webjob:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Azure.Core, Version=, 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)

Locally this works and runs.


  • Azure.Identity version 1.3.0 which has a dependency to Azure.Core version >= 1.6.0
  • Azure.Security.KeyVaults.Secrets version 4.1.0 which has a dependency to Azure.Core version >= 1.0.2

So of course based on these nuspec specifications it should resolve to Azure.Core 1.6.0. Which it locally does and runs without a problem.

Yet when I deploy this using VS publish profile to our cloud as Azure Webjobs and run the application I get the exception mentioned above. (of course the file version deployed is the same as local, version 1.6.0)

I know I can fix this with an assemblybinding. Stating that version to should resolve to version

But I find this very frustrating because it imposes manual labor and keeps us from updating packages whenever a newer version arrives because then we also have to remind ourselves to update the assemblybindings.

I feel like there is a better solution, or we are doing something wrong. But I simply do not know where to begin searching for a solution. I hope to get some insights from you guys!


This phenomenon is driving me nuts because we face similar issues when using packages:

  • Unity
  • Unity.Interception

Because they both depend on Unity.Container. Forcing us to either use assemblybinding to resolve this issue, or only use versions which depend on the same packages


1 Answer


Try doing the following steps because the approach you are taking is correct:

  • Uninstall both Azure.Identity and Azure.Security.KeyVaults.Secrets nuget packages.
  • Remove all the associated Assembly Bindings.
  • Delete bin and obj folders in your project folder.
  • Install Azure.Core version >= 1.6.0 and rebuild the solution.
  • Deploy the solution.

These should work ideally. I think that there are some stale dependencies which are getting deployed. You can also try deploying through pipelines, if not already doing.

answered on Stack Overflow Dec 14, 2020 by singhh-msft

User contributions licensed under CC BY-SA 3.0