Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Startup fails when static method is passed to WebHostBuilder.Configure #712

Closed
@nil4

Description

@nil4
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;

static class Program {
    static void Main(string[] args) => new WebHostBuilder()
        .UseKestrel()
        .Configure(ConfigureApplication)
        .Build().Run();

    static void ConfigureApplication(IApplicationBuilder app) {}
}

Expected: the application starts up and ConfigureApplication is called.

Actual: the application crashes on startup with stack trace:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Object.GetType()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.ResolveApplicationName()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildHostingServices()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at Program.Main(String[] args) in D:\projects\Repro\Program.cs:line 6

In WebHostBuilder.ResolveApplicationName, _startup.ConfigureDelegate.Target is assumed to be non-null. This assumption is invalid for static methods.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions