我一直在开发一个 ASP.NET Core Web 应用程序,主要基于 Visual Studio 2017 RC2 中提供的 MVC 模板。它在本地调试模式下运行得很好,但是当我尝试将其发布到 Azure 托管的 Web 应用程序时,出现以下错误:
启动应用程序时发生错误。
.NET Core X86 v4.1.1.0 | Microsoft.AspNetCore.Hosting 版本
1.1.0-rtm-22752 |微软视窗6.2.9200
我尝试过设置stdoutLogEnabled="true"
在web.config文件中,但似乎没有效果,错误是一样的。
Update:
在一些帮助下,我设法检索日志,它说:
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 行引用的代码行是:
services.AddMvc();
Update:
我的 global.json 文件如下所示(其中 Bla.Api 是项目的名称,该文件位于解决方案根文件夹中)。
{
"projects": [ "Bla.Api" ],
"sdk": {
"version": "1.1.0"
}
}
由于许多不同的问题都可能导致此错误页面,因此我强烈建议执行以下操作,以便快速轻松地确定根本原因,而无需费力地获取 Azure(或任何与此相关的服务器/平台)来获取日志。
您可以启用非常有帮助的启动时开发人员友好的错误消息通过设置.UseSetting("detailedErrors", "true")
and .CaptureStartupErrors(true)
Program.cs 文件中的操作。
对于 ASP.NET Core 1.x
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseSetting("detailedErrors", "true")
.UseIISIntegration()
.UseStartup<Startup>()
.CaptureStartupErrors(true)
.Build();
host.Run();
}
(2018/07) ASP.NET Core 2.1 更新
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.CaptureStartupErrors(true)
.UseSetting("detailedErrors", "true")
.UseStartup<Startup>()
.Build();
}
- 故障排除完成后应立即删除这些设置,以免您的应用程序遭受恶意攻击。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)