Roman Mik Roman Mik - 2 months ago 22
ASP.NET (C#) Question

Could not load file or assembly 'WebGrease' one of its dependencies. The located assembly's manifest definition does not match the assembly reference

I am trying to add System.Web.Optimization to my ASP.NET Web Forms solution.
I added Microsoft ASP.NET Web Optimization Framework through NuGet Packages. It added Microsoft.Web.Infrastracture and WebGrease (1.5.2) to the references.

However, when I run

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

I get runtime error

Could not load file or assembly 'WebGrease, Version=, 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)

I have tried adding assemblyBinding to the Web.Config

<legacyUnhandledExceptionPolicy enabled="1"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="" newVersion=""/>

But without any luck.

I noticed that my WebSite's Web config contains this line

<configuration xmlns="">

If I replace it with


Then everything works and I don't get the runtime error. Unfortunately, I need the xmlns. Other components of my project depend on it.

Why would Optimization try to load an older version when schema is pointing to v2.0? Is there a way to force it to load the latest or the only available WebGrease.dll?

What else can I try without changing the

<configuration xmlns=""> ?

Thank you for any help you can provide!

1) Attaching FusionLog Result. Maybe it will be helpful

=== Pre-bind state information ===
LOG: User = [USER]
LOG: DisplayName = WebGrease, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Appbase = file:///C:/Projects/PROJECT_NAME/trunk/
LOG: Initial PrivatePath = C:\Projects\PROJECT_NAME\trunk\\bin
Calling assembly : System.Web.Optimization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\PROJECT_NAME\trunk\\web.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: WebGrease, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35

2) Confirmed, The issue is in

<configuration xmlns="">

However, I don't understand why


Finally, the issue was in <configuration xmlns="">. It caused the Render method to load wrong WebGrease assembly.

Removing the xmlns solved the issue for me.