无法加载文件或程序集'System.Web.Mvc'

我的新ASP。NET MVC Web应用程序工作在我的开发工作站,但不运行在我的Web服务器…


“/”应用程序中的服务器错误。


配置错误

描述:在处理此请求所需的配置文件时发生错误。请检查下面的特定错误详细信息,并适当修改配置文件。

解析器错误信息:无法加载文件或程序集` System.Web。Mvc,版本=1.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35'或其依赖项之一。系统无法找到指定的文件。

源错误:

Line 44:         <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Line 45:         <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Line 46:         <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Line 47:         <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Line 48:         <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

源文件: C:\inetpub\www.example.org\web.config 线: 46

组件负载跟踪:下面的信息可以帮助确定为什么程序集` System.Web. web。Mvc,版本=1.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35'无法加载。

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

版本信息: Microsoft .NET Framework版本:2.0.50727.3053;ASP。净版:2.0.50727.3053


我需要在服务器上安装AspNetMVCBeta-setup.msi吗?或者服务器有不同的安装程序?

enter image description here

393902 次浏览

直接在web服务器上安装MVC是一种选择,这样程序集就会安装在GAC中。您还可以bin部署程序集,这可能有助于在最终版本可用之前,使您的服务器远离预发布程序集。

Phil Haack前几天发表了一篇关于如何在应用中部署MVC的文章,所以没有必要直接安装:

http://www.haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx

我刚刚写了一篇博客来解决这个问题。你可以安装ASP。或者你可以遵循这里的步骤. NET MVC。


我浏览了这个链接,然后遇到了与维克多 下面相同的问题,所以我建议你也添加这些:

* Microsoft.Web.Infrastructure
* System.Web.Razor
* System.Web.WebPages.Deployment
* System.Web.WebPages.Razor

我在GoDaddy共享主机上部署我的MVC3 Razor web应用程序时遇到了同样的问题。还有一些额外的.dll需要被引用。详细信息:http://paulmason.biz/?p=108

基本上,除了@ haacks的帖子中列出的引用外,您还需要添加以下引用,并将它们设置为在本地部署。

  • Microsoft.Web.Infrastructure
  • System.Web.Razor
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor
我遇到了和sgriffinusa一样的问题。 除了Phil的文章建议的引用:http://www.haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx。我添加这些:

* Microsoft.Web.Infrastructure
* System.Web.Razor
* System.Web.WebPages.Deployment
* System.Web.WebPages.Razor

Godaddy部署工作得很完美。关闭自定义错误并添加引用以纠正错误。这应该能帮你找到正确的方向。

如果你没有使用主机提供商,你可以访问服务器安装…然后安装MVC 3更新工具,这样做…它将为您在windows 2003服务器/ IIS6机器上节省数小时的问题。,我在此页上注释了dll版本号不匹配

除了Haack的帖子,Hanselman也有类似的帖子。BIN部署ASP。NET MVC 3与Razor到Windows服务器没有安装MVC

对我来说,“复制本地= true”的解决方案是不够的,因为我的网站的项目引用不包括所有丢失的dll。正如Scott在他的帖子中提到的,我还需要从我的开发盒上的以下文件夹中获得额外的dll: C:\Program Files (x86)\Microsoft ASP.NET\ASP。NET Web Pages\v1.0\程序集。错误消息告诉我丢失了哪个dll (System.Web. dll)。基础设施,包含。剃刀等)我继续添加每个丢失的dll,一个接一个,直到它工作。

在VS2010中,在解决方案资源管理器中右键单击项目并选择“添加可部署依赖项”。然后勾选下面对话框中与MVC相关的复选框。

这将在项目中创建一个'_bin_deployableAssemblies'文件夹,其中包含其他答案中提到的所有.dll文件。我相信在创建部署包时,会将这些文件复制到bin文件夹中。

简单的修复。在VS2010中,右键单击你的MVC项目,选择“Add deployyable Dependencies…”,选择你想要的选项,然后单击确定

我们想要添加它是因为我们正在创建一个使用它的类库。

对我来说,就是在这里……

C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies

在尝试了所有的方法仍然失败之后,这是我的解决方案: 我记得我上次在我的Visual studio中更新MVC版本时出错了,所以我从另一个Visual studio(不同的计算机)运行项目,然后上传dll-s,它工作了。 也许它会帮助别人…

我在。net项目中使用Jenkins,在引用MVC 4时遇到了麻烦。

我最终通过使用基于注册表的.Net参考搜索引擎功能解决了我的问题:

“HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft.NETFramework \ v2.0.50727 \ AssemblyFoldersEx”

您可以创建子键或设置默认键为“c:\myreferenceedir”为例。

它为我保存了MVC版本和ASP.net网页。

在“添加引用对话框”中添加引用非常有用

http://dhakshinamoorthy.wordpress.com/2011/12/04/how-to-register-your-net-assembly-in-gac-and-make-it-show-in-add-reference-dialog/

还要在web上检查程序集的版本。config在你的视图文件夹中,并确保它匹配。我有时会忘记还有第二个网络。在该位置配置。

有同样的问题,并添加了他们说的所有程序集,但仍然得到同样的错误。

结果你需要使"特定的版本" = False。

具体版本应为假。

我添加了“微软ASP。NET Razor”使用管理NuGet包。

在添加引用时,出于某种原因,我只有System.Web.Helpers 1.0.0和2.0.0…但不是3.0.0。

另一个选择是删除对System.Web.Mvc和System.Web.Http的引用…然后重新将它们添加到csproj文件中的包位置(你可以很容易地用文本编辑器编辑项目):

<Reference Include="System.Web.Http">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>


<Reference Include="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll</HintPath>

正如其他人所提到的,将这些引用添加到visual studio,将Copy Local设置为true。(我还必须添加System.Web.Webpages)

Microsoft.Web.Infrastructure
System.Web.Razor
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
System.Web.Webpages

在将项目转移到另一个解决方案后,我对一堆程序集文件遇到了同样的问题。

对我来说,web.config文件试图添加这个程序集:

<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

认为项目中的引用指向版本3.0.0.0(单击引用并滚动到属性底部)。因此,我只是在web.config文件中更改了引用版本。

我不知道这是否是某种错误。添加所有其他引用的问题是,这些引用出现在配置文件中,但实际上在项目中(在解决方案资源管理器中)根本没有引用,所需的文件没有与其他项目文件一起复制,可能是因为不是"copy local = true"

现在,我无法在可添加的程序集中找到这些程序集(通过右键单击引用并尝试从程序集或扩展中添加它们)。相反,我创建了一个新的MVC解决方案,它添加了我需要的所有程序集和引用,并在解决方案资源管理器中的新项目引用下找到它们,并在引用的属性窗口中找到它们的路径。

然后我只是把我需要的库复制到另一个项目中并引用它们。

我在Microsoft.AspNet.Mvc -Version 5.2.3中遇到了这个问题,在经历了所有这些线程后,我找到了一个最简单的解决方案。

只需遵循以下步骤:

  1. 在Visual studio中打开项目的NuGet包管理器
  2. 搜索Microsoft.AspNet.Mvc
  3. 当发现时,将操作更改为“卸载”并“卸载它”
  4. 完成后,重新安装并尝试
这将自动修复引用的所有问题。 见下图:

enter image description here

我已经做了“更新-包-重新安装Microsoft.AspNet”。Mvc”来修复它在Visual Studio 2015。

一个重要的考虑是网络。配置文件,一些包可以破坏你的绑定重定向造成严重破坏(流氓包是在内部包,我没有删除网页。配置从包或确保网络。配置在包中没有任何绑定重定向。例如,通过删除重复和不正确的节点来解决这个问题

    <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>




<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>




<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.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="SimpleInjector" publicKeyToken="984cb50dea722e99" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.3.2.0" newVersion="3.3.2.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="HtmlAgilityPack" publicKeyToken="bd319b19eaf3b43a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.4.9.5" newVersion="1.4.9.5"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

通过删除第8行到第24行修复构建。