I have an MVC4 Web API project. While running the service project I am getting an error
Could not load file or assembly \'WebGrease, Version=1.5.1.25624,
The other answers did not resolve this for me. We are adding a newer MVC 5 API project and it wasn't playing nice with the older MVC 2 API's. After running package updates I was getting the mentioned error. The resolution for me was to remove the WebGrease references added by NuGet in the web.config's of the offending projects.
To Resolve: Open the web.config of the project(s) throwing the exception and delete or comment out the dependency added for WebGrease.
I used "Install-Package Microsoft.AspNet.Web.Optimization"
(current version is 1.1.3) for starup web-project, which was not selected in NuGet console by default.
But NuGet has created a new app.config file even though web.config is expected to be updated.
For me it worked to move WebGrease dependentAssembly element from app.config
to web.config
's <runtime><assemblyBinding>...</assemblyBinding></runtime>
.
Alreasy resolved this error. Situation was simpler than i thought. When you install from nuget new version of System.Web.Optimization it has reference to
// References: WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35
At same time i have WebGrease version 1.5.2.14234. Running project, we have this error: Could not load file or assembly 'WebGrease, Version=1.5.1.25624
Soo, i try to check this version on nuget and was surprized, that it wasn't...but when i create new project with VS - i got it. To hack this error i try to install it in GAC..but gac says me, that this lib is not subscribed. Downgrading to System.Web.Optimization Version=1.1.0.0 , where reference is:
// References: WebGrease, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
and 1.3.0.0 is strongly subscribed - helped me. It works. After upgrading webgrease, i have it Version=1.6.5135.21930 and it worked perfectly.
At conclusion, i have an opinion, than this error (Could not load file or assembly 'WebGrease, Version=1.5.1.25624) was because of that System.Web.Optimization lib is referenced to unsubscribed webgrease dll version.
I had this issue during a deployment.
I copied WebGrease.dll to production, but I forgot to update the Web.Config file as well.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Since I wasn't able to uninstall using package manger console, I manually went to packages.config
and comment out the older version.
I've faced the excat same issue and managed to fix it by doing the following: