@@ -178,6 +178,7 @@ public IWebHostBuilder UseStartup([DynamicallyAccessedMembers(StartupLinkerOptio
178178 if ( _builder . Properties . TryGetValue ( _startupConfigName , out var startupObject ) &&
179179 object . ReferenceEquals ( startupObject , startupType ) )
180180 {
181+ _builder . Properties . Remove ( _startupConfigName ) ;
181182 UseStartup ( startupType , context , services ) ;
182183 }
183184 } ) ;
@@ -205,6 +206,7 @@ void ConfigureStartup(HostBuilderContext context, IServiceCollection services)
205206 if ( _builder . Properties . TryGetValue ( _startupConfigName , out var startupObject ) &&
206207 object . ReferenceEquals ( startupObject , startupFactory ) )
207208 {
209+ _builder . Properties . Remove ( _startupConfigName ) ;
208210 var webHostBuilderContext = GetWebHostBuilderContext ( context ) ;
209211 var instance = startupFactory ( webHostBuilderContext ) ?? throw new InvalidOperationException ( "The specified factory returned null startup instance." ) ;
210212 UseStartup ( instance . GetType ( ) , context , services , instance ) ;
@@ -325,6 +327,7 @@ public IWebHostBuilder Configure(Action<IApplicationBuilder> configure)
325327 if ( _builder . Properties . TryGetValue ( _startupConfigName , out var startupObject ) &&
326328 object . ReferenceEquals ( startupObject , configure ) )
327329 {
330+ _builder . Properties . Remove ( _startupConfigName ) ;
328331 services . Configure < GenericWebHostServiceOptions > ( options =>
329332 {
330333 options . ConfigureApplication = configure ;
@@ -349,6 +352,7 @@ public IWebHostBuilder Configure(Action<WebHostBuilderContext, IApplicationBuild
349352 if ( _builder . Properties . TryGetValue ( _startupConfigName , out var startupObject ) &&
350353 object . ReferenceEquals ( startupObject , configure ) )
351354 {
355+ _builder . Properties . Remove ( _startupConfigName ) ;
352356 services . Configure < GenericWebHostServiceOptions > ( options =>
353357 {
354358 var webhostBuilderContext = GetWebHostBuilderContext ( context ) ;
0 commit comments