【问题标题】:Could not load file or assembly System.Web.WebPages.Deployment无法加载文件或程序集 System.Web.WebPages.Deployment
【发布时间】:2014-06-04 14:44:48
【问题描述】:

我正在开发一个系统网页,突然出现这个错误:

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

【问题讨论】:

  • 你是从项目中引用它吗?

标签: c# .net .net-assembly


【解决方案1】:

请尝试以下步骤。

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

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>

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

【讨论】:

  • 我有这个条目,但仍然有问题。就像 User37... 写的那样,还需要一个 System.Web.WebPages.Deployment 的条目,这很奇怪 - publicKeyToken 是一样的。对我来说,问题是在清除全局程序集缓存后出现的,这严重扰乱了我的 .net 框架安装。
【解决方案2】:

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

在我在 MANAGE NUGET "Microsoft.AspNet.Mvc/5.1.2"、"Microsoft ASP.NET Web Pages/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>

祝你好运

【讨论】:

  • 这对我有用,但它真的让我很生气,因为这个问题突然出现在任何地方。我正在将自己从旧笔记本电脑迁移到工作中的新笔记本电脑,但我的网站拒绝加载。我尝试做各种各样的事情,这就是有效的。感谢您解决这个问题。
【解决方案3】:

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

你需要安装WebMatrix

长话短说,GAC MSIL 中缺少所需的 DLL,需要安装它们。您可以安装两个版本的 WebMatrix 1.0.0.0 和 2.0.0.0,因为它们可以很好地共存;或者只安装您需要的:

+--------------------------+---------- ---------------------------------------------------------------+-- ------------+ |安装程序名称 |网址 | 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 | +--------------------------+---------- ---------------------------------------------------------------+-- ------------+

可点击的链接

【讨论】:

  • 当我使用 VS2022 安装全新的笔记本电脑并且有一个需要安装它的 IIS 网站时,这对我有用。
【解决方案4】:

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

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

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

    • \bin
    • \obj
  2. 清理 Appdata 临时文件夹 对于我的 Win 7 机器,它位于 Windows 7 中的 C:\Users\your_username\AppData\Local\Temp\Temporary ASP.NET Files

希望这会有所帮助!

【讨论】:

    【解决方案5】:

    我通常做的是去你编译代码的机器,去dos提示符并输入这个

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

    可能有几个通常在

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

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

    【讨论】:

      【解决方案6】:

      将这段代码复制到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>
      

      【讨论】:

      • "oldVersion" 范围很大,"newVersion" 是你的[System.Web.WebPages.Deployment.dll] 版本;[dll] 版本你可以在"C:\Program文件 (x86)\Microsoft ASP.NET\ASP.NET 网页\v2.0\Assemblies"
      【解决方案7】:

      尝试将 System.Web.WebPages.dll 复制粘贴或打包安装到您的 web bin 目录中。

      您可以从 NuGet 库中获取它,

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

      确保版本匹配。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-17
        相关资源
        最近更新 更多