无法加载文件或程序集&System; Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35' ASP.NET MVC

时间:2017-09-25 00:53:24

标签: asp.net-mvc

我经历了许多以前回答的答案,但我找不到解决问题的方法并不幸运。这无法加载文件或程序集&System; Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'以及我用过的许多其他人。

****这是运行时错误:****

无法加载文件或程序集“System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个依赖项。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

异常详细信息:System.IO.FileLoadException:无法加载文件或程序集&System; Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个依赖项。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)

来源错误:

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。

程序集加载跟踪:以下信息有助于确定程序集“System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'无法加载。

===预绑定状态信息=== 日志:DisplayName = System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35  (完全指定的) 日志:Appbase = file:/// C:/ menupoly / abdulla / men1 / MenuSnaps / 日志:初始PrivatePath = C:\ menupoly \ abdulla \ men1 \ MenuSnaps \ bin

调用程序集:Microsoft.Web.Helpers,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35。

日志:此绑定在默认加载上下文中启动。 日志:使用应用程序配置文件:C:\ menupoly \ abdulla \ men1 \ MenuSnaps \ web.config 日志:使用主机配置文件:C:\ Users \ user \ Documents \ IISExpress \ config \ aspnet.config 日志:使用C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ config \ machine.config中的计算机配置文件。 日志:政策后参考:System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35 日志:尝试下载新的URL文件:/// C:/ Users / user / AppData / Local / Temp / Temporary ASP.NET Files / root / c0c49273 / dff4168 / System.Web.WebPages.Razor.DLL。 日志:尝试下载新的URL文件:/// C:/ Users / user / AppData / Local / Temp / Temporary ASP.NET Files / root / c0c49273 / dff4168 / System.Web.WebPages.Razor / System.Web.WebPages .Razor.DLL。 日志:尝试下载新的URL文件:/// C:/menupoly/abdulla/men1/MenuSnaps/bin/System.Web.WebPages.Razor.DLL。 警告:比较程序集名称导致不匹配:主要版本 错误:无法完成程序集的设置(hr = 0x80131040)。探测终止。

堆栈追踪:

[FileLoadException:无法加载文件或程序集' System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个依赖项。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)]    Microsoft.Web.Helpers.PreApplicationStartCode.Start()+ 0

[InvalidOperationException:预应用程序启动初始化方法Start on type类型Microsoft.Web.Helpers.PreApplicationStartCode抛出异常,并显示以下错误消息:无法加载文件或程序集&System; Web.WebPages.Razor, Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个依赖项。定位的程序集的清单定义与程序集引用不匹配。 (来自HRESULT的异常:0x80131040)。]    System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection 1 methods, Func 1 setHostingEnvironmentCultures)+613    System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods)+141    System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath,Boolean& isRefAssemblyLoaded)+102    System.Web.Compilation.BuildManager.ExecutePreAppStart()+157    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager,IApplicationHost appHost,IConfigMapPathFactory configMapPathFactory,HostingEnvironmentParameters hostingParameters,PolicyLevel policyLevel,Exception appDomainCreationException)+531

[HttpException(0x80004005):预应用程序启动初始化方法启动类型Microsoft.Web.Helpers.PreApplicationStartCode引发异常,并显示以下错误消息:无法加载文件或程序集&System; Web.WebPages .Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其中一个依赖项。定位的程序集的清单定义与程序集引用不匹配。 (来自HRESULT的异常:0x80131040)。]    System.Web.HttpRuntime.FirstRequestInit(HttpContext context)+9946024    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+90    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context)+261

**This is the portion of my Web.Config**

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.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="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>

I verified the version of each on Reference are the same as on Web.Config. Please help me. Thank you for your help.

8 个答案:

答案 0 :(得分:5)

你在web.config中有这个绑定重定向,其中提到正在使用Razor 2.0而不是Razor 3.0,并且你正试图使用​​不受任何限制的Razor 3.0程序集:

<dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>

首先应该做的是,将绑定重定向更改为使用版本3.0:

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

还要确保Views文件夹中的web.config中存在这些配置行:

<configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
</configSections>

如果它还没有工作&amp;您不确定Razor软件包是否已正确安装,请尝试使用NuGet Gallery / Package Manager控制台命令重新安装所需的软件包(使用-reinstall开关),然后执行以上步骤:

Update-Package –reinstall Microsoft.AspNet.WebPages

Update-Package -reinstall Microsoft.AspNet.Razor

NB - 此程序集绑定表示正在使用MVC 4:

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

我建议将MVC项目升级到5.0.0版,并按照此参考中的建议将Razor绑定更新到3.0.0版:

How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2 (Microsoft Docs)

类似问题:

Runtime error: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0

Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0

答案 1 :(得分:0)

前几天我收到同样的错误。搜索了一整天后,我找到了解决方案。

可能这可以帮到你。

1. Check your Server's Path "C:\Program Files (x86)\Microsoft ASP.NET". 
   Is there any folder named "ASP.NET MVC 4" ?

2. If not you need to install ASP.NET Framework 4 in your server. 
   (if your project is in Framework 4.0)

答案 2 :(得分:0)

当您在不是开发计算机的IIS服务器上部署应用程序时遇到与MVC相关的此类错误,这是因为您可能没有在目标计算机上安装MVC运行时。

您可以查看服务器的文件夹C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP.NET MVC 4。您应该在几个文件夹中找到,包括&#34;程序集&#34;之一。

如果没有,您可以从MS网站下载运行时。我认为这个可以工作: https://www.microsoft.com/en-us/download/details.aspx?id=30683&751be11f-ede8-5a0c-058c-2ee190a24fa6=True但你必须检查。 您还应该能够从Web Platform Installer安装MVC。

或者,如果您不希望或不能安装运行时,也可以避免安装:

要使您的应用程序在服务器上没有请求的运行时而工作,请参阅&#34;参考文献&#34;您可以在Visual Studio的文件夹中选择所有违规的程序集,并为每个程序集设置为&#34; True&#34; &#34;复制本地&#34;。 您将不得不为MVC dll执行此操作,但可能还需要其他几个,例如:System.Net.Http,System.Net.Http.Formatting.dll,System.Net.Http.WebRequest,System.Web.Http .dll,System.Web.Http.WebHost.dll等 所以它可能需要几次尝试(幸运的是,您只需要在启动时读取错误消息以获取&#34;下一个&#34;缺少DLL的名称)。

答案 3 :(得分:0)

我只是从我的主项目bin / Debug中复制了这8个文件,并将它们放入存在System.Web异常并解决了我的问题的项目中。

System.Web.WebPages
System.Web.WebPages.dll
System.Web.WebPages.Razor
System.Web.WebPages.Razor.dll
System.Web.Razor
System.Web.Razor.dll
System.Web.WebPages.Deployment
System.Web.WebPages.Deployment.dll

答案 4 :(得分:0)

还有另一个可能的原因。我今天也有同样的错误。基本上,我将一个帮助程序项目从一个解决方案导入另一个解决方案,然后出现此错误,即使新解决方案中唯一的Web项目是旧的WebForm!根本没有剃须刀!!最终,我意识到helper项目中的一个文件包含一些用于处理MVC下拉列表的代码,并且helper项目中引用了System.Web.MVC。新解决方案不需要这样做,因此删除该文件和对System.Web.MVC的引用即可解决此问题。

答案 5 :(得分:0)

我遇到了同样的问题,但是三天之内无法解决。我尝试删除.vs目录,尝试在Visual Studio 2017和2019中删除引用,但错误在这里:

在bin目录中,有某种方式(可能是从我们用来构建MS解决方案的批处理脚本中)出来的 System.Web.Mvc.dll ,显然是在启动WebForms解决方案时加载的。 删除整个bin /目录后,WebForms正常运行。

一个问题是我可以使用IIS Express启动WebForms解决方案,但是可以使用本地IIS,但这可能是另一种问题。

答案 6 :(得分:0)

将System.Web.WebPages.Deployment.dll,System.Web.WebPages.dll,System.Web.WebPages.Razor.dll手动添加到“引用”文件夹

答案 7 :(得分:0)

在尝试任何其他操作之前,

我建议手动binobj文件夹中删除所有文件,以确保新版本生成解决方案中引用的文件。

通常,从共享项目/主项目更改分支时会发生这种情况。

希望在.NET世界中节省一些精力