Question

I updated all the packages of my MVC project and I got the following error:

Could not load file or assembly 'Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Building the project with a razor (.cshtml) file open gave me more errors

Was it helpful?

Solution

Here's how I managed to solve it:

Go to the solution explorer and choose Antlr under References, right-click and say properties. Make sure the file version is the same the compiler is looking for. In my case, MSBuild wanted version 5.5.0.2, but the reference properties showed an earlier 2.x version.

All I had to do is go to the package manager console and type:

PM> update-package Antlr

Then build the project again, and in-case you get the same error for more assemblies, update them as well. Your issue will be resolved

OTHER TIPS

This can happen if you have a rogue binding redirect in your configuration file, that points to a version you don't have.

In our case, we were referencing the PostSharp 5.0.50 Nuget package, and the following was present in our config file, which was causing it to look for PostSharp version 5.0.51 instead.

<dependentAssembly>
  <assemblyIdentity name="PostSharp" publicKeyToken="b13fd38b8f9c99d7" culture="neutral"/>
  <bindingRedirect oldVersion="0.0.0.0-5.0.51.0" newVersion="5.0.51.0"/>
</dependentAssembly>

I fixed it by removing the binding redirect, because it was not necessary. You could also fix it by changing the version of the binding redirect to the same version as the Nuget package you've referenced.

I tried the above solution to update a specific package but that had no success but updating all packages did work. Using the package manager console;

update-package -Reinstall

Followed by a rebuild of the solution.

I had the same error with my MVC 5 application. Tried everything from,

  • Installing and Reinstalling the Antlr packages
  • Deleting the %TEMP% data.

Fianlly i was able to solve the problem by simply deleting all the dlls from my project's bin folder and building the project again. Though I am still not sure about the real reason for this reference error.

Update-Package -Reinstall Antlr

worked for me...

Also, when publishing ensure "Delete Existing Files" checkbox is checked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top