Show type load exception on the startup error page
This commit is contained in:
parent
54451cb6fa
commit
0b14bc135b
|
|
@ -508,6 +508,21 @@ namespace Microsoft.AspNet.Hosting.Startup
|
|||
|
||||
private static IEnumerable<Exception> FlattenAndReverseExceptionTree(Exception ex)
|
||||
{
|
||||
// ReflectionTypeLoadException is special because the details are in
|
||||
// a the LoaderExceptions property
|
||||
var typeLoadException = ex as ReflectionTypeLoadException;
|
||||
if (typeLoadException != null)
|
||||
{
|
||||
var typeLoadExceptions = new List<Exception>();
|
||||
foreach (Exception loadException in typeLoadException.LoaderExceptions)
|
||||
{
|
||||
typeLoadExceptions.AddRange(FlattenAndReverseExceptionTree(loadException));
|
||||
}
|
||||
|
||||
typeLoadExceptions.Add(ex);
|
||||
return typeLoadExceptions;
|
||||
}
|
||||
|
||||
var list = new List<Exception>();
|
||||
while (ex != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.AspNet.Hosting.Fakes
|
||||
{
|
||||
public class StartupThrowTypeLoadException
|
||||
{
|
||||
public StartupThrowTypeLoadException()
|
||||
{
|
||||
// For this exception, the error page should contain details of the LoaderExceptions
|
||||
throw new ReflectionTypeLoadException(
|
||||
classes: new Type[] { GetType() },
|
||||
exceptions: new Exception[] { new FileNotFoundException("Message from the LoaderException") },
|
||||
message: "This should not be in the output");
|
||||
}
|
||||
|
||||
public void Configure()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -74,6 +74,18 @@ namespace Microsoft.AspNet.Hosting
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartupCtorThrows_TypeLoadException()
|
||||
{
|
||||
var builder = CreateWebHostBuilder();
|
||||
var serverFactory = new TestServerFactory();
|
||||
var engine = builder.UseServer(serverFactory).UseStartup<StartupThrowTypeLoadException>().Build();
|
||||
using (engine.Start())
|
||||
{
|
||||
await AssertResponseContains(serverFactory.Application, "Message from the LoaderException</span>");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task IApplicationLifetimeRegisteredEvenWhenStartupCtorThrows_Fallback()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue