简体   繁体   English

无法加载文件或程序集“WebGrease”的依赖项之一。 定位的程序集的清单定义与程序集引用不匹配

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

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 your answer如果您找到解决此问题的新方法,请记录在您的答案中

I am trying to add System.Web.Optimization to my ASP.NET Web Forms solution.我正在尝试将 System.Web.Optimization 添加到我的 ASP.NET Web 窗体解决方案中。 I added Microsoft ASP.NET Web Optimization Framework through NuGet Packages.我通过 NuGet 包添加了 Microsoft ASP.NET Web 优化框架。 It added Microsoft.Web.Infrastracture and WebGrease (1.5.2) to the references.它在参考中添加了 Microsoft.Web.Infrastracture 和 WebGrease (1.5.2)。

However, when I run然而,当我跑

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

I get runtime error我收到运行时错误

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)

I have tried adding assemblyBinding to the Web.Config我曾尝试将 assemblyBinding 添加到 Web.Config

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

But without any luck.但没有任何运气。

I noticed that my WebSite's Web config contains this line我注意到我的网站的 Web 配置包含这一行

 <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

If I replace it with如果我用它替换它

 <configuration>

Then everything works and I don't get the runtime error.然后一切正常,我没有收到运行时错误。 Unfortunately, I need the xmlns.不幸的是,我需要 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?当模式指向 v2.0 时,为什么优化会尝试加载旧版本? Is there a way to force it to load the latest or the only available WebGrease.dll?有没有办法强制它加载最新的或唯一可用的 WebGrease.dll?

What else can I try without changing the我还能尝试什么而不改变

 <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> ?

Thank you for any help you can provide!感谢您提供的任何帮助!

Edit: 1) Attaching FusionLog Result.编辑:1) 附加 FusionLog 结果。 Maybe it will be helpful也许它会有所帮助

=== Pre-bind state information ===
LOG: User = [USER]
LOG: DisplayName = WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Projects/PROJECT_NAME/trunk/www.PROJECT_NAME.com/
LOG: Initial PrivatePath = C:\Projects\PROJECT_NAME\trunk\www.PROJECT_NAME.com\bin
Calling assembly : System.Web.Optimization, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\PROJECT_NAME\trunk\www.PROJECT_NAME.com\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=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35

2) Confirmed, The issue is in 2)确认,问题出在

<configuration  xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

However, I don't understand why然而,我不明白为什么

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>

Finally, the issue was in <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> .最后,问题出在<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> It caused the Render method to load wrong WebGrease assembly.它导致 Render 方法加载错误的 WebGrease 程序集。

Removing the xmlns solved the issue for me.删除 xmlns 为我解决了这个问题。

I modified my web.config file so that the newVersion="1.0.0.0" matched my Referenced file version:我修改了我的 web.config 文件,以便 newVersion="1.0.0.0" 匹配我引用的文件版本:

<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 .以防万一它对任何人有帮助,我遇到了同样的问题,但发现它是由 WebGrease 的依赖程序集引起的,即Antlr3 It had added the following to runtime element in web.config when installing via NuGet:通过 NuGet 安装runtime它已将以下内容添加到web.config runtime元素:

  <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.只需删除它即可解决我的问题。

In my case, the problem turned out to be an XML Processing Instruction (PI) ( <?blah ... ?> ) in my web.config file.就我而言,问题出在我的 web.config 文件中的XML 处理指令 (PI) ( <?blah ... ?> )。 Perfectly legal XML!完全合法的 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:我的 web.config 看起来类似于以下内容 - 请注意connectionStrings部分中的 XML PI:

<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!).请注意,XML PI <?blah ... ?>位于connectionStrings部分——也就是说,离assemblyBinding部分或WebGrease等的bindingRedirect条目WebGrease (这是正确的!)。

在 Web 表单站点 .net 4.5 中遇到同样的问题,将 nuget 包简单更新到最新版本对我有帮助。

I ended up with 2 runtime assemblyBinding entries for WebGrease.我最终得到了 WebGrease 的 2 个运行时 assemblyBinding 条目。 Deleting the older one (version 1.5.2) solved my issue.删除旧的(版本 1.5.2)解决了我的问题。

<dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31BF3856AD364E35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>

<dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>

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.我为我的特定问题找到的唯一临时解决方法是从其 UNC 路径而不是映射的驱动器号打开解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载文件或程序集或其依赖项之一。 找到的程序集的清单定义与程序集引用不匹配 - Could not load file or assembly or one of its dependencies. The located assembly's manifest definition does not match the assembly reference 无法加载文件或程序集XXX或其依赖项之一。 找到的程序集的清单定义与程序集引用不匹配 - Could not load file or assembly XXX or one of its dependencies. The located assembly's manifest definition does not match the assembly reference 无法加载文件或程序集“System.Web.Mvc”或其依赖项之一。 定位的程序集的清单定义与程序集不匹配 - Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. The located assembly's manifest definition does not match the assembly 无法加载文件或程序集“ Newtonsoft.Json”或其依赖项之一。 清单定义与程序集引用不匹配。 - Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. manifest definition does not match the assembly reference. Windows Universal App:无法加载文件或程序集-找到的程序集的清单定义与程序集引用不匹配 - Windows Universal App: Could not load file or assembly - The located assembly's manifest definition does not match the assembly reference 无法加载文件或程序集。 定位的程序集的清单定义与程序集引用不匹配 - Could not load file or assembly. The located assembly's manifest definition does not match the assembly reference 无法加载文件或程序集:找到的程序集的清单定义与程序集引用不匹配 - Could not load file or assembly: The located assembly's manifest definition does not match the assembly reference 无法加载文件或程序集 &#39;MySql.Data, Version=8.0.29.0.. 找到的程序集的清单定义与程序集引用不匹配 - Could not load file or assembly 'MySql.Data, Version=8.0.29.0.. The located assembly's manifest definition does not match the assembly reference 无法加载文件或程序集“AjaxControlToolkit”或其依赖项之一。 该模块应该包含一个程序集清单 - Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The module was expected to contain an assembly manifest 无法加载文件或程序集“WebGrease”或其依赖项之一 - Could not load file or assembly 'WebGrease' or one of its dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM