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."

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

问题描述

我一直在开发 ASP.NET Core Web 应用程序,主要基于 Visual Studio 2017 RC2 中提供的 MVC 模板.它在本地调试模式下运行得很好,但是当我尝试将其发布到 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:

启动应用程序时出错.

.NET Core X86 v4.1.1.0 |Microsoft.AspNetCore.Hosting 版本1.1.0-rtm-22752 |微软视窗 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:UsersuserSourceWorkspacesBlaBla.ApisrcBla.ApiStartup.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:homesitewwwroot    
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 应用程序本身,因为一切都在本地运行良好.

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.

另一个非常有用的提示是根据其他答案添加日志记录(以及根目录中的日志"文件).这至少为我指明了正确的方向.还使用 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天全站免登陆