未找到方法:'!!0[] System.Array.Empty()'

Method not found: '!!0[] System.Array.Empty()'

我使用 VS 2015 RC 和 MVC 模板创建了一个新应用程序,但没有修改任何代码行,我遇到了这个错误:

Method not found: '!!0[] System.Array.Empty()'.
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.

Exception Details: System.MissingMethodException: Method not found: '!!0[] System.Array.Empty()'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[MissingMethodException: Method not found: '!!0[] System.Array.Empty()'.]
   SAASApp.BundleConfig.RegisterBundles(BundleCollection bundles) in C:\Proyectos\SAASApp\SAASApp\App_Start\BundleConfig.cs:29
   SAASApp.MvcApplication.Application_Start() in C:\Proyectos\SAASApp\SAASApp\Global.asax.cs:18

[HttpException (0x80004005): Method not found: '!!0[] System.Array.Empty()'.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +483
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +176
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +350
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +305

[HttpException (0x80004005): Method not found: '!!0[] System.Array.Empty()'.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +661
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +96
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189

我第一次遇到这种情况,所以我现在卡住了

我在生产服务器上遇到过这种情况,而在开发机器上一切正常。

在目标机器上安装 .NET Framework 4.6 已解决问题。

很抱歉来晚了,但如果其他人通过 TeamCity 构建遇到这个问题,我可以描述我们必须做的事情。

.NET 4.6 安装在我们的构建服务器上(但没有安装在应用程序服务器上),RunnerType 是 Visual Studio (sln) 并且 Visual Studio 选项设置为 2015.

这强制构建使用 4.6,我需要将 Visual Studio 选项更改为 2013 以强制构建使用 4.5.2

仅供面临这种情况的其他人:

如果您查看 web.config 文件,您会发现在 <compilation> 标记中,您将值 targetFramework 设置为低于 4.6 的版本。但实际上,在构建时,您通过 .NET FrameWork 4.6 或更高版本发布了应用程序(对应于 ASP.NET MVC 4.6 及更高版本)。

因此,如果将 targetFramework 的值更改为 4.6,错误将变为:

The 'targetFramework' attribute currently references a version that is later than the installed version of the .NET Framework.

这是真正的错误,您可以通过在 Web 应用程序的生产环境中安装适当版本的 .Net FrameWork 来消除它。

我尝试了这些解决方案但没有成功。

我的解决方案是转到应用程序池,转到 2.0,在浏览器上执行该站点,看到错误(因为版本错误)并返回到 4.0 和 "voilà",我明白了它,网站打开了。

就我而言,我的 Windows Server 2012 R2 上安装了损坏的 .NET。我必须安装更新版本的 .NET (v4.7.1),网站现在可以正常工作了。

就我而言,我无法访问 IIS 本身,当我使用单一方法时遇到了这个问题,该方法没有任何特殊之处,只有来自 .net 2 的东西。

解决方案:我提取了该方法并使用 .net 2.0 创建了一个 Class 库并且它有效。

也许为时已晚,但我遇到了同样的问题并按如下方式修复。 我使用 Visual Studio 2015,web.config 上的配置 compilation 默认指向 .NET FrameWork 4.6。我不能只编辑 web.config 文件。如果您不能在服务器上安装 .NET FrameWork 4.6,您的应用程序就不要使用它。

  1. 转到菜单调试 > [项目名称] 属性 > 应用程序。
  2. 从 Target Framwork 下拉列表中选择 .NET Framework 4.5(或任何支持和兼容您的应用程序的服务器)。
  3. 再次重建。

我已经将 4.6.x 降级到 4.5.2,它工作正常。

将 .NET Framework 更新到最新版本 (4.7.2) 解决了该问题。 感谢@Andrey Kovalenko 的解决方案。

但是错误不应该是这样的,

我不确定告诉每个客户更新他们的 .NET Framework 是否适用。我遇到了这个问题,尤其是在 Windows 嵌入式 OS 安装的系统中,仅在生产环境中。

是否有任何其他方法可以从我们的代码库本身克服该行为?