40

When I run my MVC4 Web application it gives the following error:

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'WebGrease' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

I was having web.config as:

 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>

After refering some answers on SO , i changed it to:

<dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>

But still it's not working.

What can be the issue?

Edit:

enter image description here

Edit 2:

Again following error after installation of package:

Server Error in '/' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: Could not load file or assembly 'MySql.Web, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.

Source Error: 


Line 249:      <providers>
Line 250:        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
Line 251:        <add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
Line 252:      </providers>
Line 253:    </membership>
Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
C Sharper
  • 8,284
  • 26
  • 88
  • 151

8 Answers8

57

I had the same issue.

This was resolved by

1) running the Package Manager Console

2) in Console, type: 'Install-Package Microsoft.AspNet.Web.Optimization'

which resolved all the incorrect dependencies.

Mark
  • 2,175
  • 20
  • 23
  • 3
    after upgrade WebGrease to nuget package 1.6.0, the binding redirect was not updated. So, reinstalling Microsoft.AspNet.Web.Optimization corrected for me. After all, my web.config has the correct entry now:https://gist.github.com/jpolvora/8864750c4e3fd9f3d961 – Jone Polvora Aug 30 '14 at 00:20
  • 1
    Required the following for me: update-package -reinstall Microsoft.AspNet.Web.Optimization – Brian Riley Mar 24 '16 at 23:37
  • 1
    Works for me, Thanks..!! – Smit Patel Apr 16 '16 at 19:05
8

I had to run Update-Package -Reinstall Microsoft.AspNet.Web.Optimization

That updated my web.config and all references

Eric Herlitz
  • 25,354
  • 27
  • 113
  • 157
3

Check the contents of runtime/assemblyBinding section in web.config. I found incorrectly registered dependentAssembly elements after installing Kendo UI package. I manually removed duplicates and the problem disappeared.

3

Replace:

<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />

For:

 <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
Alex Escobar
  • 141
  • 1
  • 4
3

This problem occurs when your referenced dll may different from your web.config file configuration. You need to reinstall the dll.

Irshad
  • 3,071
  • 5
  • 30
  • 51
2

Just update WebGrease to 1.6

PM> Update-Package WebGrease -Version 1.6
Ali Umair
  • 1,386
  • 1
  • 21
  • 42
0

My situation was this: worked fine on my dev machine but got this same "webgrease missing" error on the host platform. My solution:
1. Removed all .dll's from the \bin directory
2. Removed all of the references from web.config.
3. As I refreshed the home page and got a "some-next.dll was missing" error, I copied that some-next.dll to the bin directory AND added the reference to web.config for each "fresh" dll

Note: Look at the WebGrease.dll properties | details tab - make sure the product version matched the <dependentAssembly>. In my case, it was this:

<dependentAssembly>
  <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-1.5.1.25624" newVersion="1.6.5135.21930" />
</dependentAssembly>
Gary Huckabone
  • 402
  • 3
  • 10
0

I deleted "bin", "obj" folders for project and and solution "packages" folder, then it worked.

Peheje
  • 12,542
  • 1
  • 21
  • 30