diff --git a/NuGet.config b/NuGet.config index 37f0d27e..6a62aeda 100644 --- a/NuGet.config +++ b/NuGet.config @@ -2,7 +2,7 @@ - + diff --git a/build/dependencies.props b/build/dependencies.props index 6aff4a00..9cc9e168 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,17 +1,18 @@ - + - 2.0.0-* - 2.0.1-* - 2.0.0-* - 2.0.0-* - 2.0.0-* - 4.4.1-* - 15.3.0-* + 2.0.0 + 2.0.1-rtm-15400 + 2.0.0 + 2.0.0 + 2.0.0 + 4.4.1 + 15.3.0 1.0.1 - 2.3.0-beta2-* + 2.3.0-beta2-build3683 + 2.3.0-beta2-build1317 4.7.49 1.4.0 3.2.0 - 1.5.0-* + 1.5.0 diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs index 09f159a6..f03437ab 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs @@ -191,7 +191,7 @@ private RequestDelegate BuildApplication() return builder.Build(); } - catch (Exception ex) when (_options.CaptureStartupErrors) + catch (Exception ex) { // EnsureApplicationServices may have failed due to a missing or throwing Startup class. if (_applicationServices == null) @@ -199,13 +199,18 @@ private RequestDelegate BuildApplication() _applicationServices = _applicationServiceCollection.BuildServiceProvider(); } - EnsureServer(); - // Write errors to standard out so they can be retrieved when not in development mode. Console.Out.WriteLine("Application startup exception: " + ex.ToString()); var logger = _applicationServices.GetRequiredService>(); logger.ApplicationError(ex); + if (!_options.CaptureStartupErrors) + { + throw; + } + + EnsureServer(); + // Generate an HTML error page. var hostingEnv = _applicationServices.GetRequiredService(); var showDetailedErrors = hostingEnv.IsDevelopment() || _options.DetailedErrors; diff --git a/test/Microsoft.AspNetCore.Certificates.Configuration.Tests/Microsoft.AspNetCore.Certificates.Configuration.Tests.csproj b/test/Microsoft.AspNetCore.Certificates.Configuration.Tests/Microsoft.AspNetCore.Certificates.Configuration.Tests.csproj index 71f5753d..7c9c0e9d 100644 --- a/test/Microsoft.AspNetCore.Certificates.Configuration.Tests/Microsoft.AspNetCore.Certificates.Configuration.Tests.csproj +++ b/test/Microsoft.AspNetCore.Certificates.Configuration.Tests/Microsoft.AspNetCore.Certificates.Configuration.Tests.csproj @@ -27,7 +27,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.csproj index c40c84d1..1f19e657 100644 --- a/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Hosting.FunctionalTests/Microsoft.AspNetCore.Hosting.FunctionalTests.csproj @@ -20,7 +20,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.csproj b/test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.csproj index 25757440..5974799a 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.csproj +++ b/test/Microsoft.AspNetCore.Hosting.Tests/Microsoft.AspNetCore.Hosting.Tests.csproj @@ -23,7 +23,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs index 583a231b..6353fbda 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs @@ -851,6 +851,45 @@ public async Task Build_DoesNotThrowIfUnloadableAssemblyNameInHostingStartupAsse } } + [Fact] + public void StartupErrorsAreLoggedIfCaptureStartupErrorsIsTrue() + { + var builder = CreateWebHostBuilder() + .CaptureStartupErrors(true) + .Configure(app => + { + throw new InvalidOperationException("Startup exception"); + }) + .UseServer(new TestServer()); + + using (var host = (WebHost)builder.Build()) + { + var sink = host.Services.GetRequiredService(); + Assert.True(sink.Writes.Any(w => w.Exception?.Message == "Startup exception")); + } + } + + [Fact] + public void StartupErrorsAreLoggedIfCaptureStartupErrorsIsFalse() + { + ITestSink testSink = null; + + var builder = CreateWebHostBuilder() + .CaptureStartupErrors(false) + .Configure(app => + { + testSink = app.ApplicationServices.GetRequiredService(); + + throw new InvalidOperationException("Startup exception"); + }) + .UseServer(new TestServer()); + + Assert.Throws(() => builder.Build()); + + Assert.NotNull(testSink); + Assert.True(testSink.Writes.Any(w => w.Exception?.Message == "Startup exception")); + } + [Fact] public void HostingStartupTypeCtorThrowsIfNull() { diff --git a/test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.csproj b/test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.csproj index ccd8da73..313eb4c3 100644 --- a/test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.csproj +++ b/test/Microsoft.AspNetCore.TestHost.Tests/Microsoft.AspNetCore.TestHost.Tests.csproj @@ -15,7 +15,7 @@ - + diff --git a/version.props b/version.props index eba6b167..17b3f4b9 100644 --- a/version.props +++ b/version.props @@ -1,7 +1,6 @@ - 2.0.0 - rtm + 2.0.1