Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

c# - ASP.NET Core or ASP.NET Core MVC solution fails to run, IIS Express throws HTTP Error 500.30 - ASP.NET Core app failed to start

I've been having this error happen on even the simplest "Hello world" ASP.NET Core web app in Visual Studio. (Win 10 Pro, IIS Express, VS 2019 CE.) Steps to reproduce:

  1. Create a new ASP.NET Core or ASP.NET Core MVC solution in Visual Studio 2019. Select the options to generate the scaffolding code for the basic "hello world" app. It doesn't matter whether you target .NET Core 2.1, .NET Core 3.1, or .NET 5.0, the result is the same in the scenarios I attempted.

  2. The project and solution loads and the source code is visible and looks correct. Press F5 to run it. App compiles but does not run.

Expected behavior: the "hello world" app loads.

Actual behavior: shows this error message in the web browser:

"HTTP Error 500.30 - ASP.NET Core app failed to start" (and some troubleshooting steps, then) "For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028265".

  1. Go ahead and follow that link, then use those resources to double-check that you have all the needed packages and your IIS is configured properly. Mine was all looking good on my machine, but still I was getting this error. I even tried reinstalling VS, the hosting bundle, IIS, etc. but to no avail.

NOTE: This issue is a little different than the "500.32 ANCM Failed To Load DLL" or the "500.36 ANCM Out-Of-Process Handler Load Failure" errors, but I also encountered those during my troubleshooting, so I'm mentioning them here in case it helps someone else.

NOTE ALSO: you do not necessarily have a corrupted ASP.NET Core Module as this documentation would have you believe.

  1. Check the event logs, you'll find some errors in there, but those are not particularly helpful in diagnosing the issue in this case. In my case, it just says

"Application '/LM/W3SVC/2/ROOT' with physical root 'H:Repo (R;)sandboxAspNetCoreWebApp001AspNetCoreWebApp001' failed to load coreclr. Exception message: CLR worker thread exited prematurely"

and

"Application has exited from Program.Main with exit code = '-2147450743'. Please check the stderr logs for more information."

They show IIS Express AspNetCore Module as the source. Vendor docs were not terribly helpful on this scenario.

  1. Double check to be sure you've got your IIS configration correct, and that you have the right packages installed, including the .NET Core Hosting Bundle. If you don't, or if you're trying different configurations like I was during troubleshooting, then you might see the ANCM errors mentioned above. If you get those errors, here are two links that can help. I read those links and checked my machine carefully, multiple times. In my case, this was all correct and complete, and I still had the error.

  2. Fight with the computer some more, call it some bad names, reinstall Visual Studio for the 3rd time, verify IIS settings for the 8th time, ask your friends for help, check SO and Google yet again. The simple hello world app still won't run, same error. It runs on another machine, so there's nothing wrong with the code itself.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This was the solution that eventually fixed it on my machine: I moved the solution to a different folder. HUH??? How could that possibly fix this issue, I asked. After more head-banging, I eventually arrived at the root cause: a semicolon in the path. Yup. In my case, I had been storing the solution in a directory called "H:Repo (R;)". It turns out, even though the ; character is allowed by the Windows OS, the .NET CLR does not like it at all and doesn't know what to do with it. So it generates the unhelpful error message.

Try it out. Rename the folder of your "this should be working" solution to remove the semicolons, close and reopen the solution in VS, press F5 and watch it run. Or go to a working solution and rename the folder to contain a semicolon and watch it break the CLR.

I was curious whether any other special characters in a folder name would cause an issue, so I checked them all (on folders, not on filenames, but I'd expect a similar result for filenames too). Here's my exhaustive test:

Windows disallows these in folder names:

/:*?"<>|

The solution will load and run when the path contains any of these special characters:

`~-_+=',.()[]{}!@#$%&

However, having any of these characters in the path, while being allowed by Windows, will cause issues in the CLR or in Visual Studio:

; Causes "HTTP Error 500.30 - ASP.NET Core app failed to start"

^ VS fails to load the solution & shows error message as follows:

"The following files were specified on the command line: <the .sln file> These files could not be found and will not be loaded." A totally empty instance of VS loads instead.

I also tried creating a new "hello world" console app in VS under a folder containing a semicolon in the name, and guess what? That also fails to run. Though in that case, obviously there is no HTTP error from IIS. Instead, it says

"Failed to create CoreCLR, HRESULT: 0x80070057"

and throws a process exit code. Once again, it's the result of having a semicolon in the path, because removing that semicolon from the path and reloading the solution in VS allows it to run correctly. So the semicolon issue seems to be originating from the CLR and therefore is unrelated to IIS.

Here are some related posts regarding the root cause, which is not readily apparent for web apps running on IIS Express:

Failed to create CoreCLR, HRESULT: 0x80070057

https://github.com/dotnet/sdk/issues/13954

So, kudos to those authors for those posts which were very helpful in the RCA.

One would think that the special characters allowed by the OS would also be fair game to use in the path to your Visual Studio code. Oh well. Lesson learned.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...