[c#] Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies


6 Answers

I know it's kind of late for the OP but I ran into the same problem while trying out the Bootstrap 3 for MVC 4 NuGet package, in my case it had something to do with the Microsoft.AspNet.Web.Optimization package, and managed to find a simple solution.

Try executing the following commands in the package manager console:

Install-Package Microsoft.AspNet.Web.Optimization
Update-Package WebGrease
Uninstall-Package Microsoft.AspNet.Web.Optimization
Uninstall-Package WebGrease
Install-Package Microsoft.AspNet.Web.Optimization
Update-Package WebGrease

The first two lines had no effect for me since those packages were already installed and updated by the Bootstrap 3 for MVC 4 package, but I ran them anyway and then it all compiled and ran great.

Question

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, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

i have added the WebGrease.dll file and still its coming error

and tried with changing web.config

<bindingRedirect oldVersion="0.0.0.0-1.3.0.0"/>"

and

<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />

please advice what i am missing.




When you redirect webgrease make sure you don't have an appliesTo attribute on your assemblyBinding element. For me I removed it completely.




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




For me, none of above scenarios worked.

After trying for two days, finally i found the solution.

What i did was, i uninstalled Microsoft.AspNet.Web.Optimization and WebGrease both.

I knew that this optimization assembly internally refers to WebGrease 1.5.1. So i chose a version of optimization which does not refer to WebGrease 1.5.1.

I ran following commands in order to make everything work.

Uninstall-Package Microsoft.AspNet.Web.Optimization
Uninstall-Package WebGrease
Install-Package Microsoft.AspNet.Web.Optimization -Version 1.1.0

I hope i will be able to be a good help for someone for whom above solution does not work.

Cheers!




Here is what I did to get around it,

  1. I saved a copy of the Web.config file of my current (corrupted project) to "Corrupted-Web.Config". and close the project solution.
  2. Created a new application with the same type of my courrpted project. called it ProjTemp.
  3. Save and Run the "PorjTemp", then Save a copy of the Web.Config to "OrigTemp_Web.config"
  4. Close the Web.config files.
  5. On the "ProjTemp" open Tools --> "NuGet Package Manager" --> "Manage NuGet Packages for Solutions" ---> Select to Update all related installed packages. 6 Now Open the newly updated Web.config file. Copy the get the info from the Updated "" Starting from "

<runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
             --- Copy this section to replace in the corrupted file.---
       </assemblyBinding>
</runtime>

  1. Save your project. Rebuild and Run. Hope this will help! ....

Here is the corrected one for example, VS2015.


<runtime>
           <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                 <dependentAssembly>
                        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
                        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
                 </dependentAssembly>
                <dependentAssembly>
                        <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
              </dependentAssembly>
              <dependentAssembly>
                        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
                        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /
              </dependentAssembly>
              <dependentAssembly>
                        <assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /
                </dependentAssembly>
                <dependentAssembly>
                        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
                </dependentAssembly>
                <dependentAssembly>
                        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
                 </dependentAssembly>
                 <dependentAssembly>
                        <assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                         <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
                  </dependentAssembly>
                  <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>
          </assemblyBinding>
  </runtime>

that's what I have done to fix it, Solution on Github Sami, Oweis 4 Computer




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.




Tried a lot of things but this worked for me sometimes webgrease assembly issues sometimes Web.Optimization assembly issues. This worked for me with Microsoft.AspNet.Web.Optimization 1.1.3

Update-Package WebGrease -Version 1.6



Related