Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Collections.Generic.KeyNotFoundException : The given key 'Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope' was not present in the dictionary. #175

Open
sanjeev-chevireddy opened this issue Jun 11, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@sanjeev-chevireddy
Copy link

Reqnroll Version

2.0.2

Which test runner are you using?

NUnit

Test Runner Version Number

4.0.1

.NET Implementation

.NET 6.0

Test Execution Method

Visual Studio Test Explorer

Content of reqnroll.json configuration file

No response

Issue Description

System.Collections.Generic.KeyNotFoundException : The given key 'Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope' was not present in the dictionary.
TearDown : System.Collections.Generic.KeyNotFoundException : The given key 'Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope' was not present in the dictionary.

Stack Trace: 
ConcurrentDictionary2.ThrowKeyNotFoundException(TKey key) ConcurrentDictionary2.get_Item(TKey key)
<>c.b__9_21(IServiceProvider sp)
CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context) CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) <59 more frames...> TestExecutionEngine.FireEventsAsync(HookType hookType) TestExecutionEngine.FireScenarioEventsAsync(HookType bindingEvent) TestExecutionEngine.OnScenarioEndAsync() TestRunner.OnScenarioEndAsync() CreateClaimFeature.TestTearDownAsync() GenericAdapter1.GetResult()
AsyncToSyncAdapter.Await[TResult](Func1 invoke) AsyncToSyncAdapter.Await(Func1 invoke)
SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method)
SetUpTearDownItem.RunTearDown(TestExecutionContext context)

Steps to Reproduce

We are currently migrating from SpecFlow to ReQnRoll and have encountered the issue when running the tests after migrating from SolidToken.SpecFlow.DependencyInjection to Reqnroll.Microsoft.Extensions.DependencyInjection;

Please see our Startup method as shown below

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Reqnroll.Microsoft.Extensions.DependencyInjection;

[ScenarioDependencies]
public static IServiceCollection ConfigureServices()
{
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
var connectionString = configuration["ConnectionString"];

IServiceCollection services = new ServiceCollection();
return services
.AddSingleton(ConfigReader.GetBrowserSettingsData())
.AddSingleton(ConfigReader.GetAppSettingsData())
.AddSingleton<IReportContext, ReportContext>()
.AddSingleton<INotificationHelper, NotificationHelper>()
.AddSingleton<IReportHelper, ReportHelper>()
.AddSingleton<IPlaywrightDriver, PlaywrightDriver>()
.AddSingleton<IHelper, Helper>()
.AddSingleton<IApiContext, ApiContext>()
.AddSingleton<IDataContext, DataContext>()
.AddSingleton<ILoginPage, LoginPage>()
.AddSingleton<IDbContainerFactory, CosmosContainerFactory>()
.AddSingleton(provider =>
{
//Authorisation
var client = GetCosmosClient(connectionString );
return new CosmosContainerFactory(client, "Claims");
})
}

Link to Repro Project

No response

@sanjeev-chevireddy sanjeev-chevireddy added the bug Something isn't working label Jun 11, 2024
@gasparnagy
Copy link
Contributor

@mbhoek have you seen such error before?

@mbhoek
Copy link
Contributor

mbhoek commented Jun 11, 2024

@gasparnagy It's a duplicate of solidtoken/SpecFlow.DependencyInjection#88

@sanjeev-chevireddy Can I ask you, from which version of the SpecFlow plugin are you migrating from?

@mbhoek mbhoek self-assigned this Jun 11, 2024
@ajeckmans
Copy link
Contributor

I actually encountered this in a project as well. I wrote it up to something we did wrong and since we were moving to using solely Bodi I ignored the issue.

@sanjeev-chevireddy
Copy link
Author

sanjeev-chevireddy commented Jun 11, 2024

@gasparnagy It's a duplicate of solidtoken/SpecFlow.DependencyInjection#88

@sanjeev-chevireddy Can I ask you, from which version of the SpecFlow plugin are you migrating from?

@mbhoek Specflow - 3.9.74, SolidToken.SpecFlow.DependencyInjection - 3.9.3

@mbhoek
Copy link
Contributor

mbhoek commented Jun 11, 2024

Hmm, that surprises me because I've only ever seen this problem in v3.9.3 of the SpecFlow plugin. I'll investigate.

@mcraa
Copy link
Contributor

mcraa commented Jun 14, 2024

I encountered the same error earlier but had to make it work quickly so I changed back to the default container.
Later I wanted to reproduce to open an issue, started with a new project and it was working fine. 🤷

That project was based on the playwright example from the docs. Of course, replacing Autofac with MS DI, and using newer versions of most packages.

I will try to switch in that project again to see if I can get back the error.

@mcraa
Copy link
Contributor

mcraa commented Jun 14, 2024

@mbhoek
In my case, one of my dependencies needed a ScenarioContext in the constructor (like in the example).
BoDi has that automatically but it is not there in the MS DI container.

@mbhoek
Copy link
Contributor

mbhoek commented Jun 14, 2024

@mcraa Thanks that helps a lot! I'm trying to reproduce it in a unit test before solving it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants