Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

fail: Microsoft.AspNetCore.Server.Kestrel[13] error on dotnet run #18

Closed
BryanWilhite opened this issue Jul 25, 2018 · 6 comments
Closed
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@BryanWilhite
Copy link
Owner

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLFHR51IIUV2", Request id "0HLFHR51IIUV2:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request.
Your application is running in Production mode, so make sure it has been published, or that you have built your SPA manually. Alternatively you may wish to switch to the Development environment.

   at Microsoft.AspNetCore.SpaServices.SpaDefaultPageMiddleware.<>c__DisplayClass0_0.<Attach>b__1(HttpContext context, Func`1 next)
   at Microsoft.AspNetCore.Builder.UseExtensions.<>c__DisplayClass0_1.<Use>b__1(HttpContext context)
   at Microsoft.AspNetCore.Builder.UseExtensions.<>c__DisplayClass0_2.<Use>b__2()
   at Microsoft.AspNetCore.Builder.UseExtensions.<>c__DisplayClass0_1.<Use>b__1(HttpContext context)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.<ProcessRequestsAsync>d__2.MoveNext()
@BryanWilhite BryanWilhite self-assigned this Jul 25, 2018
@BryanWilhite BryanWilhite added bug Something isn't working question Further information is requested labels Jul 25, 2018
@BryanWilhite
Copy link
Owner Author

this is .NET Core issue as this same error occurs on Windows

@BryanWilhite BryanWilhite changed the title fail: Microsoft.AspNetCore.Server.Kestrel[13] error on npm run fail: Microsoft.AspNetCore.Server.Kestrel[13] error on dotnet run Jul 25, 2018
@BryanWilhite
Copy link
Owner Author

ok i notice when running the dotnet run task on a Windows VS Code VM that has a .\Properties\launchSettings.json file, i see this:

Using launch settings from .\Songhay.Blog\Songhay.Blog\Properties\launchSettings.json...
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '.\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Microsoft.AspNetCore.SpaServices[0]
      Starting @angular/cli on port 50855...
Hosting environment: Development
Content root path: .\Songhay.Blog\Songhay.Blog
Now listening on: http://localhost:50323
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.SpaServices[0]
      > songhay.blog@2.0.0 start .\Songhay.Blog\Songhay.Blog\ClientApp
> ng serve --extract-css "--port" "50855"

** NG Live Development Server is listening on localhost:50855, open your browser on http://localhost:50855/ **

info: Microsoft.AspNetCore.SpaServices[0]
      Date: 2018-07-25T22:13:11.211Z

info: Microsoft.AspNetCore.SpaServices[0]
      Hash: 38be087882926db551a3
Time: 19894ms
chunk {inline} inline.bundle.js (inline) 3.85 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 192 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 555 kB [initial] [rendered]
chunk {styles} styles.bundle.css (styles) 63 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 19.2 MB [initial] [rendered]


info: Microsoft.AspNetCore.SpaServices[0]
      webpack: Compiled successfully.

image

the SPA default page loads as expected but any API calls fail with 404 errors the NG Live Development Server mentioned above cannot run ASP.NET Core

@BryanWilhite
Copy link
Owner Author

the "profiles" dictionary in launchSettings.json has two profiles:

  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Songhay.Blog": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:50323/"
    }
  }

in VS Code "IIS Express" does not work (throws “not supported” error) and the "Songhay.Blog" profile starts NG Live Development Server which does not support ASP.NET Core; i know that VS Code can run ASP.NET Core but the current project configuration may be preventing this

@BryanWilhite
Copy link
Owner Author

BryanWilhite commented Jul 25, 2018

i see now that dotnet run is no different from npm start when using Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0 (and would very much like to be mistaken); as a workaround, i see that i need to go through the VSCode F5 experience based on the auto-generated launch.json—however, because i have customized tasks.json, i need to make a change to "preLaunchTask" in launch.json

BryanWilhite pushed a commit that referenced this issue Jul 25, 2018
@BryanWilhite
Copy link
Owner Author

after getting guidance from my StackOverflow answer, i see that line 91 of Startup.cs makes my previous statement, ‘i see now that dotnet run is no different from npm start,’ a true statement:

image

commenting this line out would require me to run npm build before running npm run

@BryanWilhite
Copy link
Owner Author

i suppose this issue is resolved in terms of me paying attention to this line of code: spa.UseAngularCliServer(npmScript: "start")

however, the default behavior of Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0 is to bypass Kestrel when env.IsDevelopment() == true

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant