Could not load file or assembly 'WebGrease, Version=1.5.1.25624

by pinkbegemot 14. March 2015 13:27

Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x8013

 

This error may occur on a production server (IIS 7 in my case), while everything works fine in your development environment (VisualStudio 2012), even if you use IIS and not the bulit-in ASP.NET Development server.

What happens is, when you upgrade the  NuGet package  in VisualStudio 2012, VS adds the following  block to the web.config file in your project: (inside the <configuration/> ælement). This is an example from my own file:

  <runtime>

    <assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentityname="System.Web.Optimization"publicKeyToken="31bf3856ad364e35"culture="neutral"/>

        <bindingRedirectoldVersion="0.0.0.0-1.1.0.0"newVersion="1.1.0.0"/>

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentityname="WebGrease"publicKeyToken="31bf3856ad364e35"culture="neutral"/>

        <bindingRedirectoldVersion="0.0.0.0-1.1.0.0"newVersion="1.5.1.25624"/>

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

As long as everything works  on the development machine, we don’t think about the actual version of the  WebGrease.dll being used by the runtime. You might have several of them on your development machine. I have tried to  manually remove the reference to the  WebGrease.dll, then add it again to the project, but the actual version No in the above-mentioned block in web.config remained unchanged.
That is why for some time I didn’t pay attention to the fact, that the actual version of the WebGrease.dll in my project BIN folder was 1.6.x.x,. This version was also copied to the production environment.

I have read A LOT of tweaks about this issue, NONE of them worked for me. For instance, removing  xmlns="urn:schemas-microsoft-com:asm.v1"  in the top line.
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> changed nothing, but I am glad, if it  worked for he others.

Some guys out there @ Stackoverflow shared an impression, the whole block is simply being ignored by the runtime, and I had such an impression, too. 
There are also  tips, advising to remove the complete block <assemblyBinding></assemblyBinding> from the web.config file, but this doesn’t work, either. 

So, finally, I have figured out, the error message/exception must be accurate – the runtime simply can’t find the version specified in the web.config.

Thus, I suggest you check the actual version of the WebGrease.dll in the BIN folder of your project and put this version No into your bindingRedirect directive as   the new version:

        <bindingRedirectoldVersion="0.0.0.0-1.6.5135.21930"newVersion="1.6.5135.21930"/>

That should work, as it did for me. Happy coding!

The resource object with key '<key>' was not found.

by pinkbegemot 2. April 2013 15:22

One might run into this error after publishing a Web Application to IIS (7). This message actually means that ASP.NET simply can’t find the resource files, though the message text is somehow misleading.  There are comments on the Net, stating that simple copying the resource files to the appropriate folder solves the issue, but it doesn't. This might happen when you manually configure your deployed application to run in a Virtual Directory on IIS.

 SYMPTOMS

When you develop a web app in Visual Studio 2010 as a Web Project and debug it using local IIS, things work, as they should (hopefully). If you choose to use local IIS  7 and  run your application in a sub-folder of a main application (site) the Visual Studio’s function “Create Virtual Directory” will in fact create a sub-application on your IIS 7 and not a Virtual Directory. And your resource files will be found and used correctly.

 

But when you publish your application to the “WWWROOT” (or any other folder) you might come across a somewhat mysterious error message  “The resource object with key '<some key>' was not found”

 
RESOLUTION

  1. Make sure the required resource files are located in the “App_GlobalResources” folder of your application (can be the “App_LocalResources” as well)
  2. Make sure that the resource key in question is actually present in the resource files
  3. (and the winner is!) Make sure your application is configured as an Application  on IIS and not just as Virtual Directory

Change language