Pramod Lawate
Pramod Lawate

Reputation: 1021

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

Could any one explain why we are getting such errors like Could not load file or assembly. Whenever I update nuget references specially in azure sdk I end up with this error and because of lack of knowledge I was struggling to fix them very weirdly. Could you please explain this error ? I mean I can digest this error but I couldn't find the real solution for that.

I have clearly decided that I will understand this error and get to more on this platform. If you could explain this step by step, that would increase my knowledge with core productivity.

I have very limited knowledge about this type of error that we need add some code in web.config file.

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

But to be very honest I don't know how to decide which version need be replace with old and new version. I have recently added Azure.Identity nuget to my project.

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

For Example now I been struggling with this error.

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:

I know where to change to solve this error but don't know what to change.

Upvotes: 12

Views: 36836

Answers (4)

SendETHToThisAddress
SendETHToThisAddress

Reputation: 3704

For me I was able to solve this issue by upgrading/standardizing NuGet packages. I know some people have been able to solve the issue with binding redirects, but I have tried that and had it be unsuccessful. I've had this issue several times with the "could not load file or assembly", and each time I had different package versions in different projects. For instance, if my test project has Azure.Core v4.5 and my class library has v4.6, I would upgrade the lower version to 4.6 then the error goes away.

It's generally a good idea to use the same and newest stable package version across your projects anyway, so unless you really need to do a binding redirect I find this is a preferable solution.

Upvotes: 0

Libor Weigl
Libor Weigl

Reputation: 1

In my case, I have updated asp.net 5 to asp.net 6 and didn't update program.cs to replace IHostBuilder with WebApplication During the start asp.net 6 in production, I was getting exceptions that the application couldn't load the assembly.

https://gist.github.com/davidfowl/0e0372c3c1d895c3ce195ba983b1e03d#changing-the-content-root-application-name-and-environment

Upvotes: 0

Pramod Lawate
Pramod Lawate

Reputation: 1021

I have been reading this url binding-redirects content and got to know about a lot more new knowledge. I have fixed this error by adding below xml into my web.config file.

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

in order to deal with this error this portal really helpful https://nuget.info/packages/Azure.Core/1.20.0

Note: Sometimes the Nuget version is not the assembly version. So be careful.

Upvotes: 20

SteveP
SteveP

Reputation: 435

Just in case someone else finds this useful. I had the error in the live environment but all was okay in the development environment.

Simply put I had failed to update the web.config file in the live environment with the newly created assembly bindings from the development environment.

Thank you Pramod for your answer, it sent me in the right direction to resolve my issue.

Upvotes: 3

Related Questions