Subclassing Startup from StartupBase throws NotSupportedException
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 276
Description
### Describe the bug
When subclassing the `Startup`-class in a standard ASP.NET Core application from the abstract `StartupBase` type, the call to `UseStartup` (in `Program.CreateHostBuilder`) fails and throws a `NotSupportedException`.
There is no mention of `StartupBase` being deprecated or unusable. Documentation does not state anything about the usage not being supported.
### To Reproduce
#### `Program.cs`
```c#
partial class Program
{
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
// Alternatively
// webBuilder.UseStartup(ctx => new Startup(ctx));
});
}
```
ref.: https://gist.github.com/fredrikhr/407e30bc766f8046d7035bb3152c7203#file-program-cs
#### `Startup.cs`
```c#
public class Startup : StartupBase
{
private readonly WebHostBuilderContext context;
public Startup(WebHostBuilderContext context)
{
this.context = context;
}
public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
}
public override void Configure(IApplicationBuilder app)
{
}
}
```
ref.: https://gist.github.com/fredrikhr/407e30bc766f8046d7035bb3152c7203#file-startup-cs
#### Clone
```
https://gist.github.com/407e30bc766f8046d7035bb3152c7203.git
```
### Exceptions (if any)
```
System.NotSupportedException
HResult=0x80131515
Message=Microsoft.AspNetCore.Hosting.IStartup isn't supported
Source=Microsoft.AspNetCore.Hosting
StackTrace:
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at FredrikHr.GistIssues.AspnetCoreIStartup.Program.Main(String[] args)
```
### Further technical details
#### `csproj`
```xml
net5.0
```
#### `dotnet --info`
```
.NET SDK (reflecting any global.json):
Version: 5.0.400
Commit: d61950f9bf
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.400\
Host (useful for support):
Version: 5.0.9
Commit: 208e377a53
.NET SDKs installed:
5.0.400 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
```
#### Docker image
`mcr.microsoft.com/dotnet/sdk:5.0.400`
Contributor guide
Research direction
Reproduce the failure using the provided Program.cs and Startup.cs, then start at GenericWebHostBuilder.UseStartup in the stack trace and inspect how StartupBase is handled. Determine whether the behavior should be supported or documented as unsupported, and verify the chosen outcome with a regression test or documentation update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100