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

C# 无法加载文件或程序集System.Web.WebPages.Deployment,c#,.net,.net-assembly,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文件配置,一切看起来都很好。

我正在开发系统网页,突然出现以下错误:

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

我解决了这个问题,在项目的
web.config
中添加了下面的行…

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



祝你好运

请尝试以下步骤

  • 在参考资料中检查System.Web.Webpages的版本。假设您的版本为=X.X.X.X
  • 2.在网络配置中

    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>
    
    
    

    这对我有用。希望它也能对您有所帮助。

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

    要解决此问题,请执行以下步骤

  • 清理项目下列文件夹中的所有文件,或者只需单击“清理项目”和“清理解决方案”

    • \垃圾箱
    • \obj
  • 清理Appdata临时文件夹 对于我的Win 7计算机,其位于windows 7中的C:\Users\your\u username\AppData\Local\Temp\Temp临时ASP.NET文件中


  • 希望这有帮助

    我通常会去编译代码的机器,在dos提示符下键入

    C:> dir System.Web.WebPages.Depl* /s 
    
    通常情况下,可能会有几个

    c:/windows/Microsoft.Net/assembly/GAG_MSIL/System.web.WebPage/v....../
    
    检查日期并确保与
    System.Web.WebPages.dll相同
    
    将其复制到目标机器所在的箱子中。这应该可以解决问题。

    将此代码复制到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>
    
    
    
    我写了一篇长篇文章来记录这个问题,以备将来使用,但我将把解决方案放在这里供其他人使用:

    您需要安装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 | +--------------------------+---------------------------------------------------------------------+-------------+ +--------------------------+---------------------------------------------------------------------+-------------+ |安装程序名称| URL | DLL版本| +--------------------------+---------------------------------------------------------------------+-------------+ |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 | +--------------------------+---------------------------------------------------------------------+-------------+ 可点击链接

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

    你可以从NuGet画廊拿到它


    确保版本匹配。

    您是从项目中引用的吗?我有这个条目,但仍然存在问题。就像User37…写的一样,还需要System.Web.WebPages.Deployment的条目,这很奇怪-publicKeyToken也是一样的。对我来说,这个问题是在清除了全局程序集缓存后出现的,它严重破坏了我的.net framework安装。“旧版本”是一个很大的范围,“新版本”是你的[System.Web.WebPages.Deployment.dll]版本;您可以在“C:\Program Files(x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblys”中获得[dll]版本。这对我来说很有效,但这确实让我很生气,因为这个问题不知从哪里冒出来。我在工作时从一台旧的笔记本电脑迁移到一台新的笔记本电脑,我的网站拒绝加载。我尝试过做各种各样的事情,这就是成功的原因。谢谢你弄明白了。 +--------------------------+---------------------------------------------------------------------+-------------+ | 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 | +--------------------------+---------------------------------------------------------------------+-------------+