Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Port always log start exceptions to 2.0.1 #1216

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration>
<packageSources>
<clear />
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-release/api/v3/index.json" />
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-master/api/v3/index.json" />
<add key="AspNetCoreTools" value="https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
Expand Down
21 changes: 11 additions & 10 deletions build/dependencies.props
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<Project>
<Project>
<PropertyGroup>
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
<InternalAspNetCoreSdkVersion>2.0.1-*</InternalAspNetCoreSdkVersion>
<NETStandardImplicitPackageVersion>2.0.0-*</NETStandardImplicitPackageVersion>
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
<RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp2.0'">2.0.0-*</RuntimeFrameworkVersion>
<SystemDiagnosticsDiagnosticSourceVersion>4.4.1-*</SystemDiagnosticsDiagnosticSourceVersion>
<TestSdkVersion>15.3.0-*</TestSdkVersion>
<AspNetCoreVersion>2.0.0</AspNetCoreVersion>
<InternalAspNetCoreSdkVersion>2.0.1-rtm-15400</InternalAspNetCoreSdkVersion>
<NETStandardImplicitPackageVersion>2.0.0</NETStandardImplicitPackageVersion>
<NETStandardLibraryNETFrameworkVersion>2.0.0</NETStandardLibraryNETFrameworkVersion>
<RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp2.0'">2.0.0</RuntimeFrameworkVersion>
<SystemDiagnosticsDiagnosticSourceVersion>4.4.1</SystemDiagnosticsDiagnosticSourceVersion>
<TestSdkVersion>15.3.0</TestSdkVersion>
<WindowsApiSetsVersion>1.0.1</WindowsApiSetsVersion>
<XunitVersion>2.3.0-beta2-*</XunitVersion>
<XunitVersion>2.3.0-beta2-build3683</XunitVersion>
<XunitRunnerVisualStudioVersion>2.3.0-beta2-build1317</XunitRunnerVisualStudioVersion>
<MoqVersion>4.7.49</MoqVersion>
<SerilogExtensionsLoggingVersion>1.4.0</SerilogExtensionsLoggingVersion>
<SerilogFileSinkVersion>3.2.0</SerilogFileSinkVersion>
<SystemReflectionMetadataVersion>1.5.0-*</SystemReflectionMetadataVersion>
<SystemReflectionMetadataVersion>1.5.0</SystemReflectionMetadataVersion>
</PropertyGroup>
</Project>
11 changes: 8 additions & 3 deletions src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,26 @@ 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)
{
_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<ILogger<WebHost>>();
logger.ApplicationError(ex);

if (!_options.CaptureStartupErrors)
{
throw;
}

EnsureServer();

// Generate an HTML error page.
var hostingEnv = _applicationServices.GetRequiredService<IHostingEnvironment>();
var showDetailedErrors = hostingEnv.IsDevelopment() || _options.DetailedErrors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="Moq" Version="$(MoqVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="Moq" Version="$(MoqVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
</ItemGroup>

Expand Down
39 changes: 39 additions & 0 deletions test/Microsoft.AspNetCore.Hosting.Tests/WebHostBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITestSink>();
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<ITestSink>();

throw new InvalidOperationException("Startup exception");
})
.UseServer(new TestServer());

Assert.Throws<InvalidOperationException>(() => builder.Build());

Assert.NotNull(testSink);
Assert.True(testSink.Writes.Any(w => w.Exception?.Message == "Startup exception"));
}

[Fact]
public void HostingStartupTypeCtorThrowsIfNull()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualStudioVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
</ItemGroup>

Expand Down
3 changes: 1 addition & 2 deletions version.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!-- This file may be overwritten by automation. Only values allowed here are VersionPrefix and VersionSuffix. -->
<Project>
<PropertyGroup>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionSuffix>rtm</VersionSuffix>
<VersionPrefix>2.0.1</VersionPrefix>
</PropertyGroup>
</Project>