This issue has many solutions, please read all answers below, they might help you solve your problem too. If you find a new way to solve this, please document in you
I met this issue on a prod server, while everything worked fine on developer machine. These lines helped:
<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.0" newVersion="1.5.2.14234"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I modified my web.config file so that the newVersion="1.0.0.0" matched my Referenced file version:
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
met the same issue in web forms site .net 4.5 simple update nuget packages to last version helped me.
I had this same issue but it was the result of copying a solution from my local development computer to a networked drive where we store our projects. I was unable to get the reference to work properly when I opened the solution from a mapped drive and I kept receiving this error. Only temporary workaround I found for my specific issue was to open the solution from its UNC path and not the mapped drive letter.
In my case, the problem turned out to be an XML Processing Instruction (PI) (<?blah ... ?>
) in my web.config file. Perfectly legal XML! but it caused this error message to show up and had me looking in all the wrong places.
My web.config looked similar to the following - note the XML PI in the connectionStrings
section:
<configuration>
...
<connectionStrings>
<?blah ... ?>
<add name="AppDb" ... />
...
</connectionStrings>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
...
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
...
</assemblyBinding>
</runtime>
...
</configuration>
Note that the XML PI <?blah ... ?>
was in the connectionStrings
section -- that is, nowhere near the assemblyBinding
section, or the bindingRedirect
entries for WebGrease
etc (which were correct!).
Finally, the issue was in <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
. It caused the Render method to load wrong WebGrease assembly.
Removing the xmlns solved the issue for me.