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

Startup failure with rc2-20466 and dotnet rc2-002339 #695

Closed
Tratcher opened this issue Apr 11, 2016 · 2 comments
Closed

Startup failure with rc2-20466 and dotnet rc2-002339 #695

Tratcher opened this issue Apr 11, 2016 · 2 comments
Labels

Comments

@Tratcher
Copy link
Member

From @nil4 on April 10, 2016 22:23

When an exception is thrown in the constructor of a service, and that service is injected in the Configure method, the application crashes on startup, but does not include any trace of the actual exception.

I encountered the issue in a larger project, and reduced the repro to this gist. Versions of Windows, dotnet, dnvm and the content of project.lock.json are also included there. Here is the code:

sealed class Startup {
  public static void Main(string[] args) => new WebHostBuilder().CaptureStartupErrors(false)
    .UseKestrel().UseStartup<Startup>().Build().Run();

  public void ConfigureServices(IServiceCollection services) => services.AddSingleton<Crasher>();

  public void Configure(Crasher crasher) {}
}

sealed class Crasher {
  public Crasher() { throw new Exception("Crash in the constructor"); }
}

Running the repro application with -f net461 prints the following to the console before the Windows error dialog (Repro.exe has stopped working) shows up:

> dotnet run -f net461
Unhandled Exception: System.Exception: Could not resolve a service of type 'Repro.Crasher' for the parameter 'crasher' of method 'Configure' on type 'Repro.Startup'.
   at Microsoft.AspNetCore.Hosting.Startup.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at Repro.Startup.Main(String[] args)

I expected the actual exception message (Crash in the constructor) and source (Repro.Crasher) to be shown. In the real application, it took a long time to figure out the cause of the crash.

Changing to CaptureStartupErrors(true) prints the same error message, but the application does not crash; it starts listening on http://localhost:5000. However, the startup error page also does not include any details of the actual exception; the only thing it shows is:

Oops. 500 Internal Server Error
An error occurred while starting the application.

Trying to run the same repro with -f netcoreapp1.0 fails with Could not resolve coreclr path. I know things are still in flux with the new TFM, so I thought I should mention this also, just in case I missed something obvious in my project.json.

Copied from original issue: dotnet/aspnetcore#1384

@Tratcher
Copy link
Member Author

From @davidfowl on April 11, 2016 4:22

We're throwing the stack away here

/cc @Tratcher @JunTaoLuo

@nil4
Copy link
Contributor

nil4 commented Apr 15, 2016

@davidfowl @Tratcher implementation and test added; care to have another look?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants