ASP.NET Core 1.1在本地运行良好,但是在发布到Azure时显示“启动应用程序时发生错误". [英] ASP.NET Core 1.1 runs fine locally but when publishing to Azure says "An error occurred while starting the application."

查看:138
本文介绍了ASP.NET Core 1.1在本地运行良好,但是在发布到Azure时显示“启动应用程序时发生错误".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在很大程度上基于Visual Studio 2017 RC2中提供的MVC模板开发ASP.NET Core Web应用程序.它在本地调试模式下运行良好,但是当我尝试将其发布到Azure托管的Web应用程序时,出现此错误:

I've been developing an ASP.NET Core web app, based largely on the MVC template provided in Visual Studio 2017 RC2. It runs just fine in local debug mode, but when I try to publish it to an Azure hosted web app, I get this error:

启动应用程序时发生错误.

An error occurred while starting the application.

.NET Core X86 v4.1.1.0 | Microsoft.AspNetCore.Hosting版本 1.1.0-rtm-22752 | Microsoft Windows 6.2.9200

.NET Core X86 v4.1.1.0 | Microsoft.AspNetCore.Hosting version 1.1.0-rtm-22752 | Microsoft Windows 6.2.9200

我尝试在web.config文件中设置stdoutLogEnabled="true",但似乎没有效果,错误是相同的.

I've tried setting stdoutLogEnabled="true" in the web.config file, but it seems to have no effect, the error is the same.

更新:

在一些帮助下,我设法检索了日志,并显示:

With some help I managed to retrieve the log, and it says:

Application startup exception: System.TypeLoadException: Could not load type 'System.IO.File' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.    
   at Microsoft.Extensions.DependencyModel.FileWrapper.OpenRead(String path)
   at Microsoft.Extensions.DependencyModel.DependencyContextLoader.LoadEntryAssemblyContext(IDependencyContextReader reader)
   at Microsoft.Extensions.DependencyModel.DependencyContextLoader.Load(Assembly assembly)    
   at Microsoft.Extensions.DependencyModel.DependencyContext.Load(Assembly assembly)    
   at Microsoft.AspNetCore.Mvc.Internal.DefaultAssemblyPartDiscoveryProvider.DiscoverAssemblyParts(String entryPointAssemblyName)    
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services)    
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)    
   at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services)    
   at Bla.Api.Startup.ConfigureServices(IServiceCollection services) in C:\Users\user\Source\Workspaces\Bla\Bla.Api\src\Bla.Api\Startup.cs:line 73
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

Hosting environment: Production    
Content root path: D:\home\site\wwwroot    
Now listening on: http://localhost:1264    
Application started. Press Ctrl+C to shut down.

它在第73行引用的代码行是:

The line of code it refers to at line 73 is:

services.AddMvc();

更新:

我的global.json文件如下所示(其中Bla.Api是项目的名称,该文件位于解决方案的根文件夹中).

My global.json file looks like this (where Bla.Api is the name of the project, and the file sits in the solution root folder).

{
  "projects": [ "Bla.Api" ],
  "sdk": {
    "version": "1.1.0"
  }
}

推荐答案

感谢大家的建议.最后唯一可行的方法是删除我无法发布到的Azure Web应用程序,并创建一个全新的应用程序.我想也许以前运行时环境中的某些.dll仍然在徘徊或没有更新...无论是什么,重新创建它都可以.希望我不会再出现此错误,因为您不能真正在生产中做这种事情.

Thanks everyone for your suggestions. The only thing that worked in the end though is deleting that Azure web app that I couldn't publish to, and creating a brand new one. I guess maybe some of the .dlls from the previous runtime environment were still hanging around or not being updated... Whatever it was, re-creating it worked. Hopefully I don't get this error again though, because you can't really do this kind of stuff in production.

对global.json文件进行更改似乎无效.

Making changes to the global.json file seemed to have no effect.

使用模板创建全新的API也无济于事,问题出在Azure Web App本身,因为一切都在本地运行良好.

Creating an entirely new API from a template didn't help either, the issue was with the Azure Web App itself, as everything was running fine locally.

另一个非常有用的技巧是根据其他答案添加日志记录(以及根目录中的"logs"文件).这至少为我指明了正确的方向.还要使用dotnet --version检查运行时.

Another very helpful tip was to add logging (and the "logs" file in the root) as per the other answer. That at least pointed me in the right direction. Also checking your runtime with dotnet --version.

再次感谢大家的帮助!

这篇关于ASP.NET Core 1.1在本地运行良好,但是在发布到Azure时显示“启动应用程序时发生错误".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆