【问题标题】:Could not load file or assembly 'WebGrease' or one of its dependencies无法加载文件或程序集“WebGrease”或其依赖项之一
【发布时间】:2014-02-06 10:40:14
【问题描述】:

当我运行我的 MVC4 Web 应用程序时,它给出了以下错误:

Could not load file or assembly 'WebGrease' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'WebGrease' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

我将 web.config 设置为:

 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>

在参考了一些关于 SO 的答案后,我将其更改为:

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

但还是不行。

可能是什么问题?

编辑:

编辑 2:

安装包后再次出现以下错误:

Server Error in '/' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: Could not load file or assembly 'MySql.Web, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.

Source Error: 


Line 249:      <providers>
Line 250:        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
Line 251:        <add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="LocalMySqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
Line 252:      </providers>
Line 253:    </membership>

【问题讨论】:

  • 该程序集是否存在于磁盘上?
  • @scheien 如何检查?
  • 检查项目目录中的/bin/debug,或者你可以检查项目中的引用。缺少的程序集应该有一个黄色图标。
  • 您可以尝试使用 nuget 删除 Microsoft.AspNet.Web.Optimization 包吗?这也将删除WebGrease。然后重新安装Microsoft.AspNet.Web.Optimization
  • @scheien 我可以从哪里卸载它

标签: c# asp.net-mvc asp.net-mvc-4 kendo-ui


【解决方案1】:

我遇到了同样的问题。

已解决

1) 运行包管理器控制台

2) 在控制台中,输入:'Install-Package Microsoft.AspNet.Web.Optimization'

解决了所有不正确的依赖关系。

【讨论】:

  • 将 WebGrease 升级到 nuget 包 1.6.0 后,绑定重定向未更新。因此,重新安装 Microsoft.AspNet.Web.Optimization 为我更正了。毕竟,我的 web.config 现在有了正确的条目:gist.github.com/jpolvora/8864750c4e3fd9f3d961
  • 对我来说需要以下内容:update-package -reinstall Microsoft.AspNet.Web.Optimization
  • 为我工作,谢谢..!!
【解决方案2】:

我不得不跑 Update-Package -Reinstall Microsoft.AspNet.Web.Optimization

这更新了我的 web.config 和所有引用

【讨论】:

    【解决方案3】:

    检查 web.config 中 runtime/assemblyBinding 部分的内容。安装 Kendo UI 包后,我发现错误注册的dependentAssembly 元素。我手动删除了重复项,问题就消失了。

    【讨论】:

      【解决方案4】:

      替换:

      <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />

      为:

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

      【讨论】:

        【解决方案5】:

        当您引用的 dll 可能与您的 web.config 文件配置不同时,就会出现此问题。需要重新安装dll。

        【讨论】:

          【解决方案6】:

          只需将 WebGrease 更新到 1.6

          PM> Update-Package WebGrease -Version 1.6
          

          【讨论】:

            【解决方案7】:

            我的情况是这样的:在我的开发机器上运行良好,但在主机平台上出现同样的“webgrease missing”错误。 我的解决方案:
            1. 从 \bin 目录中删除所有 .dll
            2. 从 web.config 中删除所有引用。
            3. 当我刷新主页并出现“some-next.dll is missing”错误时,我将 some-next.dll 复制到 bin 目录并为每个“新鲜”dll 添加了对 web.config 的引用

            注意:查看 WebGrease.dll 属性 |详细信息选项卡 - 确保产品版本与 &lt;dependentAssembly&gt; 匹配。就我而言,是这样的:

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

            【讨论】:

              【解决方案8】:

              我删除了项目的“bin”、“obj”文件夹和解决方案“packages”文件夹,然后它就起作用了。

              【讨论】:

                猜你喜欢
                • 2014-10-01
                • 2021-12-12
                • 2012-01-14
                • 1970-01-01
                相关资源
                最近更新 更多