aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Assembly not located. Assembly binding incorrect. App config file out of sync?

Open chassq opened this issue 10 years ago • 2 comments

Sorry, for the long post. Did not know where to post this:

Ran into an issue whereby we were calling azure storage tables from dev/debug environment and getting an error that the Newtonsoft assembly could not be located.

Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Fusion log on the exception object stated: LOG: Redirect found in application configuration file: 6.0.0.0 redirected to 8.0.0.0. LOG: Post-policy reference: Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed LOG: The same bind was seen before, and was failed with hr = 0x80131040.

Looking at the app config (not web.config) file in bin\Debug\net461\win7-x64 we saw this in the assemblyBinding section.

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="6.0.0.0" newVersion="8.0.0.0" />
    <bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" />
    <bindingRedirect oldVersion="8.0.0.0" newVersion="9.0.0.0" />
    <bindingRedirect oldVersion="6.0.0.0" newVersion="9.0.0.0" />
  </dependentAssembly>

We had posted to Azure support twitter account thinking it was maybe on their end initially. They pointed us to a article ( http://stackoverflow.com/questions/21974076/could-not-load-file-or-assembly-exception-from-hresult-0x80131040 ) that seemed to suggest deleting the bin and obj directories and rebuilding. So we tried a clean project and that did not work. So we physically deleted the bin and obj directories and our app config file now looks like.

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="8.0.0.0" newVersion="9.0.0.0" />
    <bindingRedirect oldVersion="6.0.0.0" newVersion="9.0.0.0" />
  </dependentAssembly>

This in essence fixed the issue. I thought at one time it was said that assembly binding had gone away in asp net core? Not sure... At any rate just wanted to post and see if this led to a bug of some kind.

chassq avatar Jul 23 '16 13:07 chassq

Binding redirects are gone in .NET Core. You're using ASP.NET Core on .NET Framework (where they still exist). There's a known issue with the CLI where binding redirects get stale. Fix is to delete the output folder and build again and it should generate the correct ones.

davidfowl avatar Jul 23 '16 15:07 davidfowl

Ok, gotcha. Thanks for the reply David. Much appreciated!

chassq avatar Jul 24 '16 10:07 chassq