Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nil4 opened this issue Apr 10, 2016 · 2 comments
Closed

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

nil4 opened this issue Apr 10, 2016 · 2 comments

Comments

@nil4
Copy link
Contributor

nil4 commented Apr 10, 2016

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.

@davidfowl
Copy link
Member

@Tratcher
Copy link
Member

This issue was moved to aspnet/Hosting#695

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

No branches or pull requests

3 participants