无法加载文件或程序集System.Web.WebPages.Deployment

时间:2014-06-04 14:44:49

标签: c# .net .net-assembly

我正在开发系统网页并突然出现此错误:

Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

我已经验证了我的xml文件配置,一切都很好看。 这是堆栈跟踪:

[FileNotFoundException: Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +210
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +242
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +17
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +122

[ConfigurationErrorsException: Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +12480704
   System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +202
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +331
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +148
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12601936
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12441597

7 个答案:

答案 0 :(得分:7)

请尝试以下步骤。

  1. 检查参考文献中 System.Web.Webpages 的版本。说你的版本是= X.X.X.X
  2. 2.在Webconfig中

    a。首先添加程序集

    <assemblies>        
        <add assembly="System.Web.WebPages, Version=X.X.X.X, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    

    b。将程序集绑定到运行时

    <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-X.X.X.X" newVersion="X.X.X.X"/>
      </dependentAssembly>        
    </assemblyBinding>
    

    3.确保添加了正确的密钥

    <appSettings>
        <add key="webpages:Version" value="X.X.X.X"/>
    </appSettings>
    

    这对我有用。希望它也会帮助你。

答案 1 :(得分:4)

我解决了这个问题,在项目web.config中添加以下内容......

在我在MANAGE NUGET“Microsoft.AspNet.Mvc / 5.1.2”,“Microsoft ASP.NET网页/ 3.1.2”中标记之前,我尝试了一切,但没有任何作用(真的!!卸载VS并阅读了很多内容文章)

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

祝你好运

答案 2 :(得分:1)

在我的情况下,这是由于我的笔记本电脑重新启动崩溃而引用的程序集损坏。

要解决此问题,请按照以下步骤进行操作

  1. 清理项目的以下文件夹中的所有文件,或者只需单击清洁项目并清理解决方案

    • \ bin
    • \ OBJ
  2. 清理Appdata临时文件夹 对于我的Win 7机器,它位于此处:Windows 7中的用户\ your_username \ AppData \ Local \ Temp \ Temporary ASP.NET文件

  3. 希望这有帮助!

答案 3 :(得分:1)

我写了很长的post about this on my personal blog来记录该问题以备将来使用,但是我将解决方案放在这里供其他人使用:

您需要安装WebMatrix

长话短说,GAC MSIL中缺少必需的DLL,因此需要安装它们。您可以同时安装WebMatrix 1.0.0.0和2.0.0.0的两个版本,因为它们可以共存。或只安装您需要的一个:

+--------------------------+---------------------------------------------------------------------+-------------+
|      Installer name      |                                 URL                                 | DLL Version |
+--------------------------+---------------------------------------------------------------------+-------------+
| AspNetWebPages.msi       | https://www.microsoft.com/en-us/download/confirmation.aspx?id=15979 |     1.0.0.0 |
| AspNetWebPages2Setup.exe | https://www.microsoft.com/en-us/download/details.aspx?id=34600      |     2.0.0.0 |
+--------------------------+---------------------------------------------------------------------+-------------+

可点击的链接

答案 4 :(得分:0)

我通常做的是转到编译代码的机器,然后转到dos提示符并输入

C:> dir System.Web.WebPages.Depl* /s 

通常可能有几个

c:/windows/Microsoft.Net/assembly/GAG_MSIL/System.web.WebPage/v....../

检查日期并确保与System.Web.WebPages.dll相同 将其复制到目标计算机所在的bin中。这应该可以解决问题。

答案 5 :(得分:0)

在&#34;配置&#34;中复制此代码 Web.config ,将会这样做

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

答案 6 :(得分:0)

尝试在Web bin目录中复制System.Web.WebPages.dll的粘贴或软件包安装。

您可以从NuGet Gallery抓取它,

https://www.nuget.org/packages/Microsoft.AspNet.WebPages/

确保版本匹配。