【问题标题】:Method not found: '!!0[] System.Array.Empty()'找不到方法:'!!0[] System.Array.Empty()'
【发布时间】:2015-09-24 01:35:18
【问题描述】:

我使用 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

第一次发生在我身上,所以我现在卡住了

【问题讨论】:

标签: c# asp.net asp.net-mvc asp.net-mvc-3


【解决方案1】:

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

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

【讨论】:

  • PC 负载信!
  • 谢谢。最有可能发生的情况是: - 代码针对 .NET 4.6 进行编译,其中引用程序集包括 Array.Empty()。 - Roslyn 编译器发现 Array.Empty 可用,因此在生成参数所需的空数组时使用它。 - 编译后的应用程序正在尝试在 Array.Empty 不退出的 .NET 4.5 上运行。
  • 我们的 Windows 2008R2 Server 在安装后必须重启一次。
  • 在寻找答案时发现这个线程提供了更多背景为什么会发生这种情况github.com/dotnet/roslyn/issues/4889
  • 我安装了 .net461 但仍然有同样的错误。安装 net472 对我有用
【解决方案2】:

很抱歉迟到了,但如果其他人通过 TeamCity 构建遇到这个问题,我可以描述一下我们必须做什么。

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

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

【讨论】:

  • 我的一位好同事向我指出,如果您的构建代理具有 DotNetFrameworkTargetingPack4.5.2_Path TeamCity 的要求,那么您可以使用 Visual Studio 2015 构建解决方案,即使是 4.6已安装
  • 我按照@gman 的建议使用 4.5.2 开发包解决了这个问题。在您不想安装 4.6 的情况下,这似乎是一个更好的解决方案。
  • 多年后问,这是给你的@Dougc。我处于类似情况,我不想安装 4.6,我安装了 4.5.2。我仍然得到这个问题。 gman 建议的是什么??
  • @singsuyash,在项目配置中,转到代理要求。在那里您单击添加新要求。在参数名称中输入 DotNetFrameworkTargetingPack4.5.2_Path 并设置条件存在。
【解决方案3】:

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

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

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

“targetFramework”属性当前引用的版本晚于已安装的 .NET Framework 版本。

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

【讨论】:

  • 但是,在你这样做之后,根据创建应用程序时选择的项目模板,如果你安装了洞察力和 codeDom 应用程序,你可能必须像我一样卸载它们。我收到一个数组错误,可追溯到 roslyn 和 Microsoft Application Insight。
【解决方案4】:

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

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

【讨论】:

    【解决方案5】:

    就我而言,我的 Windows Server 2012 R2 上的 .NET 安装已损坏。我必须安装更新版本的 .NET (v4.7.1) 并且该站点现在可以运行。

    【讨论】:

      【解决方案6】:

      在我的情况下,我无法访问 IIS 本身,当我使用一个没有任何特殊的方法时,我遇到了这个问题,只有来自 .net 2 的东西。

      解决方案:我提取了该方法并使用 .net 2.0 创建了一个类库,它可以工作。

      【讨论】:

        【解决方案7】:

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

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

        【讨论】:

          【解决方案8】:

          我已将 4.6.x 降级到 4.5.2 并且运行良好。

          【讨论】:

            【解决方案9】:

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

            但错误不应该是这样的,

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

            有没有其他方法可以从我们的代码库本身克服这种行为?

            【讨论】:

            • 针对我的项目和所有 DLL 项目的旧版 .NET Framework (4.0 Client Profile) 也有效。 :)
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2019-07-26
            • 1970-01-01
            • 2015-01-16
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多