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

老子叫甜甜 提交于 2019-11-30 17:18:42

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>
Roman Mik

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.

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>

Just in case it helps anybody, I had the same issue, but found it was caused by a dependent assembly of WebGrease, namely Antlr3. It had added the following to runtime element in web.config when installing via NuGet:

  <dependentAssembly>
    <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
  </dependentAssembly>

Simply removing this fixed my issue.

met the same issue in web forms site .net 4.5 simple update nuget packages to last version helped me.

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!).

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!