You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
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:
sealedclassStartup{publicstaticvoidMain(string[]args)=>newWebHostBuilder().CaptureStartupErrors(false).UseKestrel().UseStartup<Startup>().Build().Run();publicvoidConfigureServices(IServiceCollectionservices)=>services.AddSingleton<Crasher>();publicvoidConfigure(Crashercrasher){}}sealedclassCrasher{publicCrasher(){thrownewException("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.
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 ofproject.lock.json
are also included there. Here is the code: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: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:Trying to run the same repro with
-f netcoreapp1.0
fails withCould 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 myproject.json
.Copied from original issue: dotnet/aspnetcore#1384
The text was updated successfully, but these errors were encountered: