asp.net-mvc 无法加载文件或程序集“System.Web.WebPages.Razor,Version=2.0.0.0,Culture=neutral,或其依赖项之一

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21375191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:29:03  来源:igfitidea点击:

Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, or one of its dependencies

asp.net-mvcrazoriis-6umbracoblogengine.net

提问by Hudson

Please somebody help me fix this issue.

请有人帮我解决这个问题。

Umbraco application as parent on IIS6 has the following version of System.Web.WebPages.Razor.

作为 IIS6 上的父级的 Umbraco 应用程序具有以下版本的 System.Web.WebPages.Razor。

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

  <system.web.webPages.razor>
  <host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory, System.Web.WebPages.Razor" />
  <pages pageBaseType="System.Web.WebPages.WebPage">
  <namespaces>
    <add namespace="Microsoft.Web.Helpers" />
    <add namespace="umbraco" />
    <add namespace="Examine" />
  </namespaces>
</pages>

Blog Engine application as virtual directory under the Umbraco application on IIS6 has the following version of System.Web.WebPages.Razor.

作为 IIS6 上 Umbraco 应用程序下的虚拟目录的博客引擎应用程序具有以下版本的 System.Web.WebPages.Razor。

<configSections>
<remove name="system.web.webPages.razor" />
</configSections>

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

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

Even after i added the dependentAssembly still nothing works for me, Am wasting more than a week on this issue, Please help.

即使在我添加了dependentAssembly 之后仍然对我没有任何作用,我在这个问题上浪费了一个多星期,请帮忙。

回答by ProNotion

Have you checked the actual version of System.Web.WebPages.Razorthat is currently deployed to your bin folder? I had a similar issue recently in a multi-project solution and one of the projects was using an older version of the assembly via Nuget which happened to be the one that ended up in the bin folder causing a similar error. In fact I'm pretty sure that it's the Umbraco Nuget package copying in the older assembly.

您是否检查过System.Web.WebPages.Razor当前部署到您的 bin 文件夹的实际版本?我最近在多项目解决方案中遇到了类似的问题,其中一个项目是通过 Nuget 使用旧版本的程序集,这恰好是最终出现在 bin 文件夹中的那个,导致了类似的错误。事实上,我很确定它是在旧程序集中复制的 Umbraco Nuget 包。

回答by Hudson

Finally, I have fixed this issue. Blog Engine's(Child application) Razor Script version is 2.0.0.0 and Umbraco(Parent application) 4.1.6 application's Razor script version is 1.0.0.0, i have added the below in child's web.config

最后,我已经解决了这个问题。博客引擎的(子应用程序)Razor 脚本版本是 2.0.0.0 和 Umbraco(父应用程序)4.1.6 应用程序的 Razor 脚本版本是 1.0.0.0,我在孩子的 web.config 中添加了以下内容

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

Once the above added, i get rid of this error and i faced the same dependency errors for the below and i added the respective dependent assembly and the version.

添加上述内容后,我摆脱了此错误,并且我在下面遇到了相同的依赖项错误,并添加了相应的依赖程序集和版本。

Microsoft.Web.Helpers.dll 
Examine.dll
Umbraco.dll
WebGrease.dll

For the above three dependency will not present in child application's bin folder, you need to copy the dll files from parent bin folder and add it in child bin folder, which will sort all the dependency issues.

由于以上三个依赖都不会出现在子应用的bin文件夹中,需要从父bin文件夹中复制dll文件并添加到子bin文件夹中,这样可以对所有依赖问题进行排序。

For any deploying issues on BlogEngine as virtual directory and Umbraco as parent application, leave your message will help you solve the issue of any different versions.

对于任何在 BlogEngine 作为虚拟目录和 Umbraco 作为父应用程序的部署问题,留下您的消息将帮助您解决任何不同版本的问题。

回答by amelvin

@ProNotion is right, I have seen more and more packages on Umbraco relying on specific versions of assemblies causing assemblies to conflict especially if two packages need different versions of the same assembly.

@ProNotion 是对的,我在 Umbraco 上看到越来越多的包依赖于特定版本的程序集,导致程序集冲突,尤其是当两个包需要同一程序集的不同版本时。

So some other tips:

所以一些其他的提示:

This tool from MS helps diagnose assembly binding problems (http://msdn.microsoft.com/en-us/library/e74a18c4%28v=vs.71%29.aspx).

MS 的这个工具有助于诊断程序集绑定问题 ( http://msdn.microsoft.com/en-us/library/e74a18c4%28v=vs.71%29.aspx)。

Adding a runtime / assemblyBinding section to your web.config can work round problems with clashing assemblies (http://msdn.microsoft.com/en-us/library/0ash1ksb(v=vs.110).aspx)

将运行时/程序集绑定部分添加到您的 web.config 可以解决冲突程序集的问题(http://msdn.microsoft.com/en-us/library/0ash1ksb(v=vs.110).aspx

Sometime the assembly doesn't get copied (eg you use msbuild and the assembly isn't included in the project) - so you should also check to see if the assembly made it to the live server.

有时不会复制程序集(例如,您使用 msbuild 并且该程序集未包含在项目中)-因此您还应该检查该程序集是否已到达实时服务器。

回答by Liakat

Please try the following steps.

请尝试以下步骤。

  1. Check the Version of System.Web.Webpagesin your References. Say Your Version is=X.X.X.X
  1. 检查参考文献中System.Web.Webpages的版本。说你的版本是=XXXX

2.In Webconfig

2.在Webconfig中

a.Add the assembly first

a.先添加程序集

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

b.Bind the assembly for runtime

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

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

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

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

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

回答by Grey Wolf

Sometime, you will have mistake between

有时,您之间会出错

System.Web.WebPages.Razor
and
System.Web.Razor

Try look and check

尝试查看并检查

回答by Dale Fraser

Create a new Area, right click project, Add, Area

新建一个Area,右键项目,Add,Area

Copy the web.config from the views folder in this area to /views/web.config

将该区域的views文件夹中的web.config复制到/views/web.config

remove the area

删除该区域