From 7ac6842d1864fd97c417abd016440893c3384b12 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 22 May 2017 15:47:53 -0700 Subject: [PATCH] #1075 Suppress exceptions from failing to load HostingStartup assemblies --- src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs | 6 ------ .../WebHostBuilderTests.cs | 9 +++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs index 5bd5ba6a..7774de93 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -285,12 +285,6 @@ private IServiceCollection BuildCommonServices(out AggregateException hostingSta if (exceptions.Count > 0) { hostingStartupErrors = new AggregateException(exceptions); - - // Throw directly if we're not capturing startup errors - if (!_options.CaptureStartupErrors) - { - throw hostingStartupErrors; - } } } diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs index 1e51be38..be0e86c5 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs @@ -975,7 +975,7 @@ public void Build_HostingStartupFromPrimaryAssemblyCanBeDisabled() } [Fact] - public void Build_ThrowsIfUnloadableAssemblyNameInHostingStartupAssemblies() + public void Build_DoesntThrowIfUnloadableAssemblyNameInHostingStartupAssemblies() { var builder = CreateWebHostBuilder() .CaptureStartupErrors(false) @@ -983,9 +983,10 @@ public void Build_ThrowsIfUnloadableAssemblyNameInHostingStartupAssemblies() .Configure(app => { }) .UseServer(new TestServer()); - var ex = Assert.Throws(() => builder.Build()); - Assert.IsType(ex.InnerExceptions[0]); - Assert.IsType(ex.InnerExceptions[0].InnerException); + using (builder.Build()) + { + Assert.Equal("0", builder.GetSetting("testhostingstartup")); + } } [Fact]