我昨天运行了Windows Update,当我尝试发布我的ASP.NET MVC 4项目的新版本时,它引入了一些问题。
应用程序在本地编译并运行正常,但是当我将版本推送到我的网络服务器上的测试站点时,它会出现错误消息:
System.Web.HttpCompileException: (0): error CS1705: Assembly 'App_Code, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
经过一番研究后,我发现这是由于从4.0.0.0更新到4.0.0.1。我从我的项目中删除了System.Web.Mvc dll并读取了具有更高版本的dll。一切都在本地工作,但不在网络上。然后我浏览了web.config并将任何提及的4.0.0.0更改为4.0.0.1。同样,这继续在内部工作但在外部失败。错误消息是:
Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, 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) 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 'System.Web.Mvc, Version=3.0.0.0, 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) 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. Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded. WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
我相信这与Elmah有关,我正在使用它来处理错误。
我尝试按照此处的建议从Nuget重新安装:Windows update caused MVC3 and MVC4 stop working但是这没有用,我收到同样的错误。
添加信息: 服务器尚未更新,我担心更新此服务可能会破坏现有的实时版本。
答案 0 :(得分:9)
错误消息告诉我您在其中一个配置文件中为MVC程序集指定了错误的版本号。找到包含不正确版本的配置文件,并将其更改为与您使用的任何版本匹配(您在上面提到的4.0.0.1)。您需要检查所有配置文件,包括
您也可以在配置文件中执行assembly redirect以处理此问题 - 如果由于第三方lib而失败,则可能是最合适的操作。
根据您的反馈ID建议使用绑定重定向。将其添加到主web.config ..
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.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.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
答案 1 :(得分:0)
我有类似的问题,MS更新将MVC.dll从3.0.0.0更改为3.0.0.1。我需要维护我的软件的各种版本,以确保兼容性我必须将3.0.0.0 dll复制到我的项目并在构建项目之前将其引用到那里。
答案 2 :(得分:0)
在深入了解之后,我发现view文件夹中的web.config指向不同版本的System.web.mvc。一旦我改为
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
来自
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
将System.Web.MVC的版本从4.0.0.1更改为4.0.0.0 我能够解决这个问题。