无法加载文件或程序集“WebGrease”或它的一个依赖

问题描述:

运行我MVC4 Web应用程序它给了我以下错误:无法加载文件或程序集“WebGrease”或它的一个依赖

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> 

但它仍然无法正常工作。

可能是什么问题?

编辑:

enter image description here

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

请帮助我,我是在MVC4 Kendu申请首次工作。

+0

做装配存在磁盘上? – scheien

+0

@scheien如何检查? –

+0

检查项目目录中的/ bin/debug,或者您可以切入项目中的引用。缺失的组件应该有一个黄色的图标。 – scheien

我有同样的问题。

这通过

1)运行包管理控制台

2)在控制台中,类型解决: '安装-封装Microsoft.AspNet.Web.Optimization'

从而解决所有的错误的依赖关系。

+3

升级后的WebGrease到nuget包1.6.0,绑定重定向没有更新。所以,重新安装Microsoft.AspNet.Web.Optimization纠正了我。毕竟,我的web.config现在有正确的条目:https://gist.github.com/jpolvora/8864750c4e3fd9f3d961 –

+0

Jone Polvora,为我解决了这个问题。 – AshleyS

+0

对我来说需要以下内容:update-package -reinstall Microsoft.AspNet.Web.Optimization –

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

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

这更新我的web.config和所有的参照

替换:

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

出现此问题磨片您引用的dll可能与您的web.config文件配置不同。您需要重新安装该DLL。

刚刚更新WebGrease 1.6

PM> Update-Package WebGrease -Version 1.6