Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have installed the Microsoft ASP.NET Web Optimization Framework 1.1.3 via NuGet. It installed just fine I believe. This is a .NET 4.0 Web Forms Project.

When I try to bundle I get an error. My code in Application_Start:

var jqueryBundle = new ScriptBundle("~/scripts/bundles/jquery");

    jqueryBundle.Include(new string[] { 
        "~/scripts/libs/jquery/jq/jquery-1.11.0.min.js",
        "~/scripts/swyft/mobileinit.min.js",
        "~/scripts/libs/jquery/jqm/142/lib/jquery.mobile-1.4.2.min.js",
    });

    BundleTable.Bundles.Add(jqueryBundle);

Then on one of my aspx pages...

<%= System.Web.Optimization.Scripts.Render("~/scripts/bundles/jquery") %>

Gives me this error:

An unexpected error has occurred. 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: 0x80131040)

But it is there! I am running VS2013.

Thanks for any help!

~Red

EDIT - My WebConfig:

<runtime>
<assemblyBinding appliesTo="v2.0.50727" 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>

EDIT - CANNOT INSTALL Web Grease 1.5.1:

When I try to install Web Grease 1.5.1 I get this error:

You cannot call a method on a null-valued expression.
At L:\MY_PROJECT_PATH\packages\WebGrease.1.5.1\tools\install.ps1:45 char:5
+     $msbuild.Xml.AddProperty("WebGreaseLibPath", $relativePackageUri.ToString(). ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

** EDIT - ADD package.config FILE **

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AjaxControlToolkit" version="7.1213" targetFramework="net40" />
<package id="AjaxMin" version="5.10.5260.16959" targetFramework="net40" />
<package id="Antlr" version="3.4.1.9004" targetFramework="net40" />
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net40" />
<package id="Microsoft.AspNet.ScriptManager.WebForms" version="5.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net40" />
<package id="Microsoft.Data.Edm" version="5.6.1" targetFramework="net40" />
<package id="Microsoft.Data.Services.Client" version="5.6.1" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net40" />
<package id="System.Spatial" version="5.6.1" targetFramework="net40" />
<package id="WebGrease" version="1.6.0" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="4.0.1" targetFramework="net40" />
</packages>

Edit - Added SS of Error

Error Screenshot

like image 682
Red2678 Avatar asked May 28 '14 20:05

Red2678


2 Answers

Since the latest versions apparently have dependency problems, I reluctantly went back to older versions of Optimization and Webgrease using these commands in NuGet Package Manager Console:

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

This combination worked for me, but there might be other combinations.

like image 57
Dave Avatar answered Sep 30 '22 03:09

Dave


I think the version is different for both the WebGrease and Microsoft.AspNet.Web.Optimization are different. so, try to uninstall both and update these with Nuget. After uninstalling verify your package.config file both the versions are removed or not. After that Update and observe the web.config files.

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

If its not work then verify the C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.AspNet.Web.Optimization and remove it and re-install thid again

like image 40
Pavan Kumar Manda Avatar answered Sep 30 '22 03:09

Pavan Kumar Manda