找不到方法:’!! 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文件,您将意识到在标记中,您将值targetFramework设置为低于4.6的版本。 但事实上,在构建时,您通过.NET FrameWork 4.6或更高版本发布了您的应用程序(对应于ASP.NET MVC 4.6及更高版本)。

因此,如果将targetFramework的值更改为4.6,则错误会将形状更改为:

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

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

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

对我来说,解决方案是转到应用程序池,转到2.0,在浏览器上执行该站点,看到错误(因为版本错误)并转回4.0和“voilà”,我得到它,网站打开。

就我而言,我的Windows Server 2012 R2上安装了一个损坏的.NET。 我不得不安装更新版本的.NET(v4.7.1),该网站现在正在运行。

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

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

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

  1. 转到菜单Debug> [Project Name] Properties> Application。
  2. 从Target Framwork下拉列表中选择.NET Framework 4.5(或任何服务器支持并兼容您的应用程序)。
  3. 再次重建。

我已将4.6.x降级到4.5.2并且工作正常。