簡體   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

這個問題有很多解決方案,請閱讀下面的所有答案,它們也可能幫助您解決問題。 如果您找到解決此問題的新方法,請記錄在您的答案中

我正在嘗試將 System.Web.Optimization 添加到我的 ASP.NET Web 窗體解決方案中。 我通過 NuGet 包添加了 Microsoft ASP.NET Web 優化框架。 它在參考中添加了 Microsoft.Web.Infrastracture 和 WebGrease (1.5.2)。

然而,當我跑

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

我收到運行時錯誤

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)

我曾嘗試將 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>

但沒有任何運氣。

我注意到我的網站的 Web 配置包含這一行

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

如果我用它替換它

 <configuration>

然后一切正常,我沒有收到運行時錯誤。 不幸的是,我需要 xmlns。 我項目的其他組件依賴於它。

當模式指向 v2.0 時,為什么優化會嘗試加載舊版本? 有沒有辦法強制它加載最新的或唯一可用的 WebGrease.dll?

我還能嘗試什么而不改變

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

感謝您提供的任何幫助!

編輯:1) 附加 FusionLog 結果。 也許它會有所幫助

=== 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)確認,問題出在

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

然而,我不明白為什么

我在生產服務器上遇到了這個問題,而在開發者機器上一切正常。 這些行有幫助:

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

最后,問題出在<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> 它導致 Render 方法加載錯誤的 WebGrease 程序集。

刪除 xmlns 為我解決了這個問題。

我修改了我的 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>

以防萬一它對任何人有幫助,我遇到了同樣的問題,但發現它是由 WebGrease 的依賴程序集引起的,即Antlr3 通過 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>

只需刪除它即可解決我的問題。

就我而言,問題出在我的 web.config 文件中的XML 處理指令 (PI) ( <?blah ... ?> )。 完全合法的 XML! 但它導致出現此錯誤消息,並使我在所有錯誤的地方查找。

我的 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>

請注意,XML PI <?blah ... ?>位於connectionStrings部分——也就是說,離assemblyBinding部分或WebGrease等的bindingRedirect條目WebGrease (這是正確的!)。

在 Web 表單站點 .net 4.5 中遇到同樣的問題,將 nuget 包簡單更新到最新版本對我有幫助。

我最終得到了 WebGrease 的 2 個運行時 assemblyBinding 條目。 刪除舊的(版本 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>

我遇到了同樣的問題,但這是將解決方案從我的本地開發計算機復制到我們存儲項目的網絡驅動器的結果。 當我從映射驅動器打開解決方案時,我無法使參考正常工作,並且我一直收到此錯誤。 我為我的特定問題找到的唯一臨時解決方法是從其 UNC 路徑而不是映射的驅動器號打開解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM