[英]Could not load file or assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies
[英]Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies
我有一個 MVC4 Web API 項目。 運行服務項目時出現錯誤
無法加載文件或程序集“WebGrease,版本=1.5.1.25624,文化=中性,PublicKeyToken=31bf3856ad364e35”或其依賴項之一。 系統找不到指定的文件。
我已經添加了 WebGrease.dll 文件,但仍然出現錯誤
並嘗試更改 web.config
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0"/>"
並且
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
我知道 OP 有點晚了,但是我在嘗試Bootstrap 3 for MVC 4 NuGet 包時遇到了同樣的問題,就我而言,它與Microsoft.AspNet.Web.Optimization包有關,並設法找到一個簡單的解決方案。
嘗試在包管理器控制台中執行以下命令:
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
前兩行對我沒有影響,因為這些包已經由Bootstrap 3 for MVC 4包安裝和更新,但我還是運行了它們,然后它全部編譯並運行良好。
此錯誤是因為Microsoft.AspNet.Web.Optimization 1.1.3
內部引用了WebGrease 1.5.1.25624
即使 Nuget 包本身依賴於WebGrease 1.5.2.14234
。 顯然有人在創建 Nuget 包時搞砸了。
要解決此問題,請在您的Web.Config
添加此程序集綁定。
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.1.25624" newVersion="1.5.2.14234" />
</dependentAssembly>
您是否嘗試過 NuGet ?
Install-Package WebGrease -Version 1.5.1
或
Install-Package WebGrease -Version 1.5.2
對我來說,上述情況都沒有奏效。
嘗試了兩天,終於找到了解決辦法。
我所做的是,我卸載了Microsoft.AspNet.Web.Optimization和WebGrease 。
我知道這個優化程序集內部是指 WebGrease 1.5.1。 所以我選擇了一個不涉及 WebGrease 1.5.1 的優化版本。
我運行以下命令以使一切正常。
Uninstall-Package Microsoft.AspNet.Web.Optimization
Uninstall-Package WebGrease
Install-Package Microsoft.AspNet.Web.Optimization -Version 1.1.0
我希望我能夠為上述解決方案不起作用的人提供很好的幫助。
干杯!
我觀察到的問題與 Jidheesh Rajan 提到的非常吻合。 但是,從 Nuget 包管理器更新包(不指定版本)並沒有解決問題。 這是我必須做的來解決這個問題。 (本質上,我明確地將 WebGrease 更新到了 1.6 版)
在 Visual Studio 的包管理器控制台中,將 WebGrease 顯式更新到版本 1.6 。 這是命令。
Install-Package WebGrease -Version 1.6
輸出應該是
Removing 'WebGrease 1.5.2' from {project name}
將“WebGrease 1.6.0”添加到{project name} 成功地將“WebGrease 1.6.0”添加到{project name} 卸載“WebGrease 1.5.2”。 成功卸載“WebGrease 1.5.2”。
這最終更新了 web.config
assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /
bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"
這也導致從 csproj 文件中刪除了一行。
<WebGreaseLibPath>..\packages\WebGrease.1.5.2\lib</WebGreaseLibPath>
以及 csproj 文件中此節點的更新
<Reference Include="WebGrease, Version=1.5.2.14234, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>
對此
<Reference Include="WebGrease, Version=1.6.5135.21930, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>
請記住,我在本地機器上沒有問題,只是在舞台 Web 服務器上。 我想盡最大努力在不更新軟件包的情況下解決問題,但這是我唯一的修復方法。
嘗試了很多東西,但這對我有用,有時是 webgrease 程序集問題,有時是 Web.Optimization 程序集問題。 這對我有用 Microsoft.AspNet.Web.Optimization 1.1.3
Update-Package WebGrease -Version 1.6
老歌但金...
我正在 Visual Studio 2013 中處理 MVC 5 項目,我遇到了同樣的問題。 我們使用 Visual SVN 進行版本控制,我是團隊中唯一遇到此問題的人。
唯一對我有用的是:
- 卸載 Microsoft.AspNet.Web.Optimization
- 在 Nuget 命令提示符下運行: install-package Microsoft.AspNet.Web.Optimization -Version 1.0.0
這將安裝舊版本的 Web.Optimization。 該項目最初引用版本 1.1.0。 問題不在於 WebGrease,而在於 System.Web.Optimization.dll 引用了舊的、不存在的 WebGrease 版本。
當我運行該項目時,它起作用了,但我想使用與團隊其他成員相同的包版本。 所以,我嘗試更新,但是......錯誤返回......
在此之后,我(再次)刪除了該項目並將其從 SVN 中取回。 令我驚訝的是,它開始工作了......問題是我已經完全刪除了該項目並在此之前多次從SVN中取出它。 我什至從同事那里拿走了 dll,因為我認為我可能會從 NuGet 獲取損壞的文件,但無濟於事。
我希望這會幫助某人,有一天......使用 Visual Studio 2016 和 MVC 8 :)
由於我無法使用包管理器控制台卸載,我手動轉到packages.config
並注釋掉舊版本。
我為 starup web-project使用了"Install-Package Microsoft.AspNet.Web.Optimization"
(當前版本為 1.1.3),默認情況下未在 NuGet 控制台中選擇它。
但是NuGet已經創建了一個新的 app.config文件,即使 web.config 預計會更新。
對我來說,將 WebGreasedependentAssembly元素從app.config
移動到web.config
的<runtime><assemblyBinding>...</assemblyBinding></runtime>
。
其他答案並沒有為我解決這個問題。 我們正在添加一個較新的 MVC 5 API 項目,但它與較舊的 MVC 2 API 並不兼容。 運行包更新后,我收到了提到的錯誤。 我的解決方案是刪除由 NuGet 在違規項目的 web.config 中添加的 WebGrease 引用。
解決方法:打開拋出異常的項目的web.config,刪除或注釋掉為WebGrease添加的依賴項。
已經解決了這個錯誤。 情況比我想象的要簡單。 當您從 nuget 新版本的 System.Web.Optimization 安裝時,它參考了
// 參考:WebGrease,版本=1.5.1.25624,Culture=neutral,PublicKeyToken=31bf3856ad364e35
同時我有 WebGrease 版本 1.5.2.14234。 運行項目,我們有這個錯誤:無法加載文件或程序集 'WebGrease,版本 = 1.5.1.25624
Soo,我嘗試在 nuget 上檢查此版本並感到驚訝,它不是......但是當我用 VS 創建新項目時 - 我明白了。 為了解決這個錯誤,我嘗試在 GAC 中安裝它..但是 gac 告訴我,這個庫沒有被訂閱。 降級到 System.Web.Optimization Version=1.1.0.0 ,其中參考是:
// 參考:WebGrease,版本=1.3.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35
和 1.3.0.0 被強烈訂閱 - 幫助了我。 它有效。 升級 webgrease 后,我有它 Version=1.6.5135.21930 並且運行良好。
最后,我有一個意見,比這個錯誤(無法加載文件或程序集'WebGrease,版本 = 1.5.1.25624)是因為 System.Web.Optimization 庫引用了未訂閱的 webgrease dll 版本。
我在部署期間遇到了這個問題。
我將 WebGrease.dll 復制到生產環境,但我也忘記更新 Web.Config 文件。
<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.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
這是我為解決它所做的,
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
--- Copy this section to replace in the corrupted file.---
</assemblyBinding>
</runtime>
這是更正的,例如 VS2015。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<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>
</assemblyBinding>
</runtime>
如果您不將 Web.config 文件部署到 Web 服務器,也可能會出現此問題。
VS 2017 似乎存在不部署 web.config 的問題,即使文件的屬性設置為“始終復制”。 在我的項目中,我必須為各種部署方案換出不同的 web.config 文件。 如果未部署文件,則會出現“webgrease”錯誤。
只需驗證 web.config 文件是否已部署。
我遇到了同樣的問題,並通過執行以下操作設法解決了它:
就我而言,上述任何解決方案都無法解決此問題。 與 webgrease 相關的錯誤實際上是一個紅鯡魚......這是一個無效(且完全不相關)的程序集綁定重定向的問題。 我猜想我的 web.config 文件的這個問題導致所有程序集綁定重定向失敗,而且碰巧這導致了 WebGrease 的運行時問題。
基本上,在合並過程中,其中一個綁定重定向已損壞,並且在單個<dependentAssembly>
標記中出現了兩個程序集重定向。
因此,如果您遇到此問題並且您已經為 WebGrease 正確設置了綁定重定向,則值得掃描所有其他程序集綁定重定向以檢查它們是否已損壞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.