这个问题有很多的解决方案,请阅读下面的所有答案,它们可能会帮助你解决你的问题。如果您找到了解决这个问题的新方法,请在您的答案中记录
我正在尝试将System.Web.Optimization添加到ASP.NET Web解决方案中。我通过ASP.NET包添加了。它在引用中添加了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=31bf3856ad364e352)确认,该问题在
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">但是,我不明白为什么
发布于 2014-01-13 19:15:35
最后,这个问题出现在<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">上。它导致呈现方法加载错误的WebGrease程序集。
删除xmlns为我解决了这个问题。
发布于 2014-05-06 02:50:48
我在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>发布于 2014-03-25 17:06:57
我修改了我的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>https://stackoverflow.com/questions/20908895
复制相似问题