1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
using Microsoft.AspNetCore.Hosting; //IWebHostBuilder using Microsoft.AspNetCore.Builder; //IApplicationBuilder using Microsoft.AspNetCore.Http; //WriteAsync using Microsoft.AspNetCore; //webHost using Microsoft.Extensions.Logging;//ILoggerFactory using Microsoft.Extensions.DependencyInjection; // IServiceCollection using Microsoft.Extensions.Primitives; //StringValues using System; //Exception namespace WebApplication1 { public class Startup { public Startup(IHostingEnvironment env, ILoggerFactory logger) { //These are two services available at constructor } public void ConfigureServices(IServiceCollection services) { throw new Exception("error here"); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger) { app.Run(context => { return context.Response.WriteAsync($"Request {context.Request.Method}"); }); } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseSetting("detailedErrors", "true") .UseStartup<Startup>() .UseEnvironment("Development"); //You can change this to "Production" to use StartupProduction } } |
결과 :
An error occurred while starting the application.
Exception: error here
WebApplication1.Startup.ConfigureServices(IServiceCollection services) in Program.cs, line 21
Exception: error here
WebApplication1.Startup.ConfigureServices(IServiceCollection services) in Program.cs
21. throw new Exception(“error here”);
Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Show raw exception details
.NET Core 4.6.28008.02 X64 v4.0.0.0 | Microsoft.AspNetCore.Hosting version 2.2.7-servicing-10089 | Microsoft Windows 10.0.18362 | Need help?