aspnetcore: Microsoft.AspNetCore.Mvc.Testing is broken in SDK 6.0.201

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

ObjectDisposedException thrown when trying to use the WebApplicationClient targeting SDK 6.0.201.
When reverting to SDK 6.0.200, the issue goes away.

Expected Behavior

ObjectDisposedException should not be thrown.

Steps To Reproduce

Write any test that calls WebApplicationFactory.CreateClient()

Exceptions (if any)

 System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'ConfigurationManager'.
   at Microsoft.Extensions.Configuration.ReferenceCountedProviderManager.AddProvider(IConfigurationProvider provider)
   at Microsoft.Extensions.Configuration.ConfigurationManager.AddSource(IConfigurationSource source)
   at Microsoft.Extensions.Configuration.ConfigurationManager.Microsoft.Extensions.Configuration.IConfigurationBuilder.Add(IConfigurationSource source)
   at Microsoft.AspNetCore.Builder.WebApplicationBuilder.<>c__DisplayClass25_0.<Build>b__2(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
   at Program.<Main>$(String[] args) in D:\GIT\Whds.Packing.App\src\Whds.Packing.StateMachine\Program.cs:line 53

.NET Version

6.0.201

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (10 by maintainers)

Most upvoted comments

Minimal repro without Convey:

var builder = WebApplication.CreateBuilder(args);

var sp = build.Services.BuildServiceProvider();
_ = sp.GetRequiredService<IConfiguration>();
sp.Dispose();

var app = builder.Build();

Edit: You can likely workaround the issue by passing builder.Configuration to AddConvey()

builder.Services.AddConvey(configuration: builder.Configuration);

Looks like the issue isn’t related to only the WebApplicationFactory. The exception is also thrown at runtime.

image

If that’s your scenario it’s covered by my initial comment #40614 (comment) and is fixed in a change coming in 6.0.4

Cool, thanks for your help!