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

 Phoenix-Valefor 发布于 2023-02-06 17:59

这个问题有很多解决方案,请阅读下面的所有答案,它们也可以帮助您解决问题.如果您找到解决此问题的新方法,请在答案中记录

我试图将System.Web.Optimization添加到我的ASP.NET Web窗体解决方案.我通过NuGet包添加了Microsoft ASP.NET Web Optimization Framework.它将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


  
    
      
        
        
      
    

但没有任何运气.

我注意到我的WebSite的Web配置包含这一行

 

如果我用它替换它

 

然后一切正常,我没有得到运行时错误.不幸的是,我需要xmlns.我项目的其他组件依赖于它.

为什么当架构指向v2.0时,Optimization会尝试加载旧版本?有没有办法强制它加载最新或唯一可用的WebGrease.dll?

如果不改变,我还能尝试什么

  ?

感谢您提供任何帮助!

编辑: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)确认,问题在于


但是,我不明白为什么

3 个回答
  • 我修改了我的web.config文件,以便newVersion ="1.0.0.0"与我的Referenced文件版本匹配:

    <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.0.0.0" />
      </dependentAssembly>
    

    2023-02-06 18:01 回答
  • 最后,问题出在了<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">.它导致Render方法加载错误的WebGrease程序集.

    删除xmlns解决了我的问题.

    2023-02-06 18:01 回答
  • 我在prod服务器上遇到了这个问题,而在开发人员机器上一切正常.这些行帮助:

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

    2023-02-06 18:02 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有