且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET Core 或 ASP.NET Core MVC 解决方案无法运行,IIS Express 抛出 HTTP 错误 500.30 - ASP.NET Core 应用程序无法启动

更新时间:2022-11-06 16:03:34

这是最终在我的机器上修复它的解决方案:我将解决方案移到了不同​​的文件夹. HUH??? 我问,这怎么可能解决这个问题.经过一番折腾,我终于找到了根本原因:路径中有一个分号.是的.就我而言,我一直将解决方案存储在名为H:\Repo (R;)"的目录中.事实证明,即使 Windows 操作系统允许使用 ; 字符,.NET CLR 根本不喜欢它,也不知道如何处理它.因此它会生成无用的错误消息.

试试看.重命名这应该可以正常工作"的文件夹解决方案删除分号,关闭并重新打开VS中的解决方案,按F5并观察它运行.或者转到工作解决方案并将文件夹重命名为包含分号,然后观察它是否会破坏 CLR.​​

我很好奇文件夹名称中的任何其他特殊字符是否会导致问题,所以我检查了所有这些字符(在文件夹上,而不是文件名上,但我希望文件名也有类似的结果).这是我的详尽测试:

Windows 不允许在文件夹名称中使用这些:

\/:*?"<>|

当路径包含以下任何特殊字符时,解决方案将加载并运行:

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

但是,在 Windows 允许的路径中包含这些字符中的任何一个都会导致 CLR 或 Visual Studio 中的问题:

; 导致HTTP 错误 500.30 - ASP.NET Core 应用程序无法启动">

^ VS 加载失败解决方案 &显示错误信息如下:

"在命令行中指定了以下文件:<.sln 文件>无法找到这些文件,也不会加载这些文件."而是加载了一个完全空的 VS 实例.

我还尝试创建一个新的你好世界";VS 中的控制台应用程序位于名称中包含分号的文件夹下,你猜怎么着?这也无法运行.虽然在这种情况下,显然 IIS 没有 HTTP 错误.相反,它说

未能创建 CoreCLR,HRESULT:0x80070057"

并抛出进程退出代码.再一次,这是路径中有分号的结果,因为从路径中删除该分号并在 VS 中重新加载解决方案可以使其正确运行.所以分号问题似乎源于CLR,因此与IIS无关.

以下是一些有关根本原因的相关帖子,这对于在 IIS Express 上运行的 Web 应用程序并不明显:

未能创建 CoreCLR,HRESULT:0x80070057

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

因此,感谢那些对 RCA 非常有帮助的帖子的作者.

有人会认为操作系统允许的特殊字符也可以用于 Visual Studio 代码的路径中.那好吧.吸取的教训.

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;)\sandbox\AspNetCoreWebApp001\AspNetCoreWebApp001' 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.

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.