首页 > 解决方案 > Lamar 在使用 ServiceRegistry 时导致 500.30 错误

问题描述

我使用 Lamar 作为 .Net Core (2.2) Web API 的 DI。

程序.cs

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseLamar()
                .UseStartup<Startup>();
    }

当我在 Startup.cs 有以下代码时,程序启动正常。

        public void ConfigureServices(IServiceCollection services)
        { }

一旦我将方法更改为此

        public void ConfigureServices(ServiceRegistry services)
        { }

启动 Web API 将显示

HTTP Error 500.30 - ANCM In-Process Start Failure

在事件查看器中有几个错误。

Application '/LM/W3SVC/2/ROOT' with physical root 'C:\xxx\path\to\Web.API\' hit unexpected managed exception, exception code = '0xe0434352'. Please check the stderr logs for more information.

Application '/LM/W3SVC/2/ROOT' with physical root 'C:\xxx\path\to\Web.API\' failed to load clr and managed application. CLR worker thread exited prematurely

标签: .net.net-corelamar

解决方案


这个错误是因为我刚刚用ServiceRegistry 替换了ConfigureServices调用。我实际上应该使用ConfigureContainer

        public void ConfigureContainer(ServiceRegistry services)
        { }

推荐阅读