Could not load file or assembly System.Web.WebPage

2019-01-26 06:55发布

Im working developing a system web page and suddenly appears this error:

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.

I already verify my xml files configuration, and everything look good. This is the stack trace:

[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

5条回答
闹够了就滚
2楼-- · 2019-01-26 07:07

copy this code in the "configuration" of Web.config,that will do it

  <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>
查看更多
手持菜刀,她持情操
3楼-- · 2019-01-26 07:10

I resolved this problem adding line below in web.config of project...

Before I marked in MANAGE NUGET "Microsoft.AspNet.Mvc/5.1.2", "Microsoft ASP.NET Web Pages/3.1.2", I try anything but nothing works (really!! uninstall VS and read a lot articles)

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

Good lucky

查看更多
We Are One
4楼-- · 2019-01-26 07:15

In my case this was due to corrupted assembly being referenced which happened due to crash restart of my laptop.

To fix this please following these steps

  1. Clean all the files in the following folders of your project or you can simply click on clean project and clean solution

    • \bin
    • \obj
  2. Clean the Appdata temp folder for my Win 7 machine its located here C:\Users\your_username\AppData\Local\Temp\Temporary ASP.NET Files in windows 7

Hope this helps!

查看更多
冷血范
5楼-- · 2019-01-26 07:16

Please try the following steps.

  1. Check the Version of System.Web.Webpages in your References. Say Your Version is=X.X.X.X

2.In Webconfig

a.Add the assembly first

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

b.Bind the assembly for runtime

<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.Make sure you have added correct key

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

This worked for me. Hope It'll help you too.

查看更多
我命由我不由天
6楼-- · 2019-01-26 07:18

What I usually do is go to the machine where you compile you code and go to dos prompt and type this

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

There might be several of them usually in

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

check the date and make sure is the same as System.Web.WebPages.dll copy it to the bin where your target machine is. This should fix the problem.

查看更多
登录 后发表回答