question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
BrennanConroycommented, Mar 9, 2022

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);
2reactions
philip-reedcommented, Mar 9, 2022

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

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

CS2015 ~\6.0.201\Sdks\Microsoft.NET.Sdk.Web\analyzers ...
When i try to compile my asp.net core 5.0 application i am getting this error -Error CS2015 'C:\Program Files\dotnet\sdk\6.0.201\Sdks\Microsoft.
Read more >
Why I couldn't use Microsoft.AspNetCore.Mvc; in my unit ...
AspNetCore.Mvc in unit testing project because unit testing project is a separate project and it does not contain library Microsoft.AspNetCore.
Read more >
NETSDK1045: The current .NET SDK does not support ...
This error occurs when the build tools can't find the version of the .NET SDK that's needed to build a project. This is...
Read more >
NET 6 MVC enabling razor runtime compilation breaks ...
I followed the simple steps at https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-6.0&tabs=visual-studio ...
Read more >
Microsoft.AspNetCore.Mvc.Testing 7.0.10
Version Downloads Last updated 8.0.0‑preview.7.23375.9 3,329 12 days ago 8.0.0‑preview.6.23329.11 7,333 a month ago 8.0.0‑preview.5.23302.2 5,236 2 months ago
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found