90

I'm getting this error while trying to run my MVC4 project, it was working fine until last time on my other machines, but when I'm trying to run it from another machine it's giving me this error:

Could not load file or assembly 'Antlr3.Runtime (1)' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

After reading about this here I've tried to do:

Install-Package Antlr3.Runtime -Pre

but it didn't help, any ideas?

4
  • 1
    Did you try un installing the prev. version before installing the above version?
    – Spock
    Commented Nov 24, 2013 at 21:29
  • 1
    I didnt updated any version. Just changed the machine
    – user971741
    Commented Nov 24, 2013 at 21:30
  • Did you try to right-click on solution and then on "Enable nuget package restore"?
    – T.S.
    Commented Nov 24, 2013 at 22:11
  • None of the answers here helped, but the answer to this duplicate did.
    – DCShannon
    Commented Oct 9, 2014 at 21:50

27 Answers 27

106

I encountered the same problem when experimenting with the free Nlog logging platform.

This helped me:

Enter %TEMP% in the File Explorer and delete all the temporary files.

After that I didn't get the error when starting my MVC5 project in Visual Studio.

3
  • My error message didn't have the "(1)", but this solution still worked
    – Roberto
    Commented May 22, 2015 at 16:26
  • 13
    Thanks for this. It's Microsoft crap like this that sometimes makes you want to put your fist through the guts of Visual Studio...
    – Smyrnian
    Commented Jul 2, 2015 at 6:40
  • Awesome!! Wasted too many hours on this. My issue was not the build part but publishing the artifacts using the pubxml files was failing on the Jenkins Server, while it was working fine on my local machine. Once deleting the temp folder as described above, the publish artifacts worked without issues.
    – yyardim
    Commented Oct 31, 2017 at 17:18
43

Try to delete the temporary files for ASP.Net by doing one of these:

  • Enter %TEMP% in the File Explorer and delete all the temporary files.
  • Go to folder "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files" and delete all files.
2
  • 7
    Thank you. For me it was option 2 that helped
    – Rabbi
    Commented May 22, 2014 at 11:07
  • I agree with @Rabbi. It's option 2 that solved my issue. I wish I could upvote your answer 10 times! THank you very much. :) Commented Jul 28, 2017 at 5:17
31

Don't forget to clear also the Temporary ASP.NET Files in Framework64. That did the trick for me.

  • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
  • C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
2
  • Perfect thanks, tried the accepted answer to no avail until I saw this post, the Framework64 did it for me Commented Mar 28, 2015 at 18:46
  • This works for my and another project-dll referenced. In my case all the references in Web project were broken, the message was: "Could not load file or assembly 'whatever.dll' or one of its dependencies". After clean up, dll reference could was created and all works fine.
    – Fer R
    Commented Feb 1, 2017 at 15:45
30

Just in case this helps someone.
I had this problem with an MVC 5 Application. Deleting Antlr3.Runtime.dll from the bin directory and re-building fixed the issue.

3
  • This worked for me. Thanks. But i am still not sure about the real reason for this error. Can someone explain. Commented Mar 28, 2016 at 7:17
  • 1
    In my case, I had to delete WebGrease.dll instead
    – Tharwen
    Commented Jan 3, 2017 at 17:15
  • thank you... spent 3 hours trying to get this resolved and this is the step that got rid of my YSOD.
    – Joshua K
    Commented Jun 26, 2019 at 13:35
19

For me, removing this node in the web.config file got rid of the error message:

<identity impersonate="true" userName="" password="">

But what really worked for me was granting full access (to the userName specified in impersonate), to the Temporary ASP.NET Files" folder found in C:\Windows\Microsoft.NET\Framework{version} (or Framework64).

The identity might also be stored in the Web Site Application Pool Settings, in IIS.

Make sure your nuget package is correctly installed, with the correct version. If nothing else works, then just try re-adding the reference from a local folder and setting it to Copy Local.

5
  • 1
    This solved the issue for me. the web.config had a setting for impersonation in staging environment and that user account did not exist in my dev world.
    – ttomsen
    Commented Jul 16, 2014 at 17:49
  • I tried all three suggestions and none of them worked. Still getting a YPOD 1. There is not <identity tag in my web.config 2. I gave 'full control' to both iis_usrs & users\johnny 3. Last options seems like a hack Commented Mar 18, 2015 at 11:05
  • I solved it by using the command : ASPNET_REGIIS -GA impersonatedusername
    – cslecours
    Commented Feb 6, 2017 at 15:47
  • This helped to solve my problem. I was working locally and as account name mentioned in this element has no access to my dev folder.
    – Aamol
    Commented Sep 27, 2018 at 0:15
  • Thanks, this solution is really helpful. Commented Sep 22, 2020 at 16:31
19

My problem was that the latest version of WebGrease installs version 3.4.1.9004 of Antlr. Once I installed WebGrease and then updated Antlr to version 3.5.0.2, the error went away.

1
  • 12
    My problem was exactly this issue. I had to unwind the dependency chain in the Package Manager Console by uninstalling Microsoft.AspNet.Web.Optimization, WebGrease and Antlr (in that order), then install-package Microsoft.AspNet.Web.Optimization, update-package WebGrease and finally update-package Antlr (in that order) to get the latest versions and correct the Antlr version issue.
    – Wade
    Commented Dec 13, 2014 at 2:03
12

If any solutions solve your problem verify the web.config, the version of assembly

<dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
2
  • Thanks.In the case of updating packages and face the problem ,this answer worked for me.
    – fbarikzehy
    Commented Jun 29, 2015 at 5:06
  • I removed this assembly , then its worked for me. Thank you!! Commented Oct 23, 2017 at 6:10
11

The one of the simple way is update antlr and webgrease

  1. Goto Package console manager
  2. then try apply these codes one by one
  3. PM>Update-Package Antlr
  4. PM>Update-Package WebGrease

Finally the Error Solved

0
3

There was problem with impersonate="true" in web.config, i removed the line it worked !!

Again i placed the line and gave admin permission to account user with impersonate, my whole application worked :)

2

For me this was caused by a mismatch between the debug and runtime versions of Antlr.

Finally solved it by installing a different Antlr package: Install-Package Antlr

2

Try to unlock the Antlr3.Runtime.dll if you add reference manually: enter image description here

2

If you're using impersonation. The answer is to give permission for the user that you're impersonating access to the following folders :

  1. C:\Windows\Microsoft.NET\Framework[v4.0.30319 or the version that you're using]\Temporary ASP.NET Files

  2. Your site directory.

also you might need to create folder as the following :

C:\Windows\Microsoft.NET\Framework\[v4.0.30319 or the version that you're using]\Temporary ASP.NET Files\[Application-Name-Goes-Here]

But try the previous first, it worked for me.

Those two changes for granting the impersonated user permission to be able to save the temp data, and pull the dll files, and any needed files from the directories

Update, For windows 10 This is the solution that worked for me

We will do both steps, but Instead of C:\Windows\Microsoft.NET\Framework[v4.0.30319 or the version that you're using]\Temporary ASP.NET Files

Write %TEMP% into the file explorer, and give permission for the user that you're impersonating access to the following folder: C:\Users\[UserName]\AppData\Local\Temp\Temporary ASP.NET Files

1

I got a simple solution. Go to your own project folder and find a packages folder.

enter image description here

0

In a project I had reference to WebGrease, but there was not corresponding element in packages.config. I remove the reference from project, because I don't need it anymore. It works now.

0

I tried all of the answers in this post, but none of them worked for me.

So I deleted all of the /bin directories inside all of the projects from my solution, cleaned and rebuilt the solution and it finally worked!

My whole morning wasted working to figure out the problem...

0

what worked for me was removing the identity = true from my webconfig (under the system.web properties) and build the solution again and publish it again (if needed) and it worked like a charm!

1
  • this should be in comment Commented Apr 4, 2016 at 12:56
0

My problem ended up being caused by a change to the mapped drives in our Group Policy. My solution has the tempDirectory setting set in the Web.config to use a RAM drive setup as my Z: drive. Apparently they started using the Z: drive and the DLLs were getting copied to tempDirectory like normal, but then I think they were being deleted by a process on the remote server (Virus scan probably). I was only able to figure this out by using Process Monitor and filtering for Antlr and seeing that it was looking in a network location for the DLLs.

0

I updated all packages in the Nudget Package Manager and it worked! In my case I'm hosting my website in GoDaddy

0

After trying to delete .netframework temp file without success, I changed

<system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime />
    <pages controlRenderingCompatibilityVersion="4.0" />
</system.web> 

With only targetFramework="4.6" instead of 4.6.1 Web site displays without errors. Next I changed again to targetFramework="4.6.1" and restart server. Everything remains Ok.

0

For me, the solution was to run Visual Studio as Administrator. It was apparently a permissions issue.

0

Solution for me was to go Tools > NuGet Package Manager > Manage Packages for Solution

Then click Antlr3 and ensure it was installed in:

  1. The Startup Project
  2. Any libraries using reflection
  3. Any libraries calling the libraries that use reflection

In my case that was 4 Projects deep that needed it. Once that was done this issue was finally resolved.

0

I just faced this issue and tried above mentioned solutions but nothing worked for now I had to delete it's dll from bin floder and rebuild and then delete all releated files from packages folder and restore packages using package manager console

0

Deleted %temp%

Deleted bin

Deleted .vs

Now worked for me

0

In my case, when I cloned a project, Visual studio 2019 replaced a spaces character with '% 20' in the project's path. Then, when VS tried to find the nugget packages, it could not find the correct path.

0

I faced this issue after upgrading Microsoft.AspNet.Web.Optimization

update-package WebGrease and update-package Antlr (in that order) to get the latest versions and correct the Antlr version issue.

0

For me, I did these steps and it's worked for me :

1 ) I deleted bin and obj folder (some files was not deleted by Clean project)

2 ) I checked some files like JS that was deleted a long time ago but they was included in project files. So I exclude them.

0

This worked for me :

Tools > NuGet Package Manager > Manage Packages for Solution

Install de Antlr3.Runtime

enter image description here

Microsoft Visual Studio Community 2019 (2) Version 16.10.3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.