Search code examples
c#azure-sdk-.netazure-identity

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.


Solution

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