Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

The given key 'Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope' was not present in the dictionary. #88

Closed
VladislavKutsTAQA opened this issue Jun 7, 2022 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@VladislavKutsTAQA
Copy link

C#, .net core 5.0. Specflow 3.10.2, SolidToken.SpecFlow.DependencyInjection 3.9.3
All hooks are running, after i get this issue.
I've added and implemented this nuget like this:

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using POS.BusinessLogic.Database.Employee;
using POS.BusinessLogic.DetailContainer;
using POS.BusinessLogic.Requests.Payment;
using POS.BusinessLogic.Requests.Pops;
using POS.BusinessLogic.Requests.Stall;
using POS.BusinessLogic.Services.PaymentEmulator;
using POS.BusinessLogic.Services.PopsEmulator;
using POS.BusinessLogic.Services.StallEmulator;
using POS.Core.Environment;
using POS.Core.Nats;
using POS.Core.StallStorage;
using Serilog;
using Serilog.Core;
using SolidToken.SpecFlow.DependencyInjection;

namespace POS.Steps.Hooks
{
public static class CreateServicesHooks
{
[ScenarioDependencies]
public static IServiceCollection CreateServices()
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();

        var services = new ServiceCollection();

        services
            .Configure<DbOptions>(configuration.GetSection("dpOptions"))
            .Configure<NatsOptions>(configuration.GetSection("natsOptions"))
            .Configure<AppOptions>(configuration.GetSection("appOptions"))
                
            .AddSingleton<INatsConnectionFactory, NatsConnectionFactory>()
            .AddSingleton<INatsSender, NatsSender>()
            .AddSingleton<INatsReader, NatsReader>()
            
            .AddSingleton<IDbEmployee, DbEmployee>()
            
            .AddSingleton<IContainer, Container>()
            
            .AddSingleton<IPopsRequests, PopsRequests>()
            .AddSingleton<IStallRequests, StallRequests>()
            .AddSingleton<IPaymentRequests, PaymentRequests>()
            
            .AddSingleton<IPopsService, PopsService>()
            .AddSingleton<IStallService, StallService>()
            .AddSingleton<IPaymentEmulator, PaymentEmulator>()
            
            .AddSingleton<Logger>();
    
        return services;
    }
}

}

StackTrace:
System.Collections.Generic.KeyNotFoundException : The given key 'Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope' was not present in the dictionary.
at System.Collections.Concurrent.ConcurrentDictionary2.ThrowKeyNotFoundException(TKey key) at System.Collections.Concurrent.ConcurrentDictionary2.get_Item(TKey key)
at SolidToken.SpecFlow.DependencyInjection.DependencyInjectionPlugin.<>c.b__9_22(IServiceProvider sp)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at SolidToken.SpecFlow.DependencyInjection.DependencyInjectionTestObjectResolver.ResolveBindingInstance(Type bindingType, IObjectContainer container)
at TechTalk.SpecFlow.ScenarioContext.GetBindingInstance(Type bindingType)
at lambda_method37(Closure , IContextManager , String , EmployeeInfo )
at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBindingAsync(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, DurationHolder durationHolder)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatchAsync(BindingMatch match, Object[] arguments, DurationHolder durationHolder)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepAsync(IContextManager contextManager, StepInstance stepInstance)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStepAsync()
at TechTalk.SpecFlow.TestRunner.CollectScenarioErrorsAsync()
at POS.FeatureFiles.InStore.Basket.Item.ItemDisplayFeature.ScenarioCleanupAsync()
at POS.FeatureFiles.InStore.Basket.Item.ItemDisplayFeature.ClientCanSeeSplitLabelIfOrderWasSplitted() in C:\pops-automation\POS.FeatureFiles\InStore\Basket\Item\ItemDisplay.feature:line 55
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter1.GetResult() at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func1 invoke)
at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.b__0()
at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

@mbhoek mbhoek self-assigned this Jun 7, 2022
@mbhoek mbhoek added the bug Something isn't working label Jun 7, 2022
@mbhoek
Copy link
Member

mbhoek commented Jun 7, 2022

@VladislavKutsTAQA Thanks for your report. I notice you are using Specflow 3.10.2-beta which introduces async features for the first time. I haven't tested the plugin against this beta version yet.

However the exception occurs in a piece of code that was rewritten in the last version, so would you be so kind to try using v3.9.2 of the SpecFlow.DependencyInjection plugin and see if it still happens?

@VladislavKutsTAQA
Copy link
Author

VladislavKutsTAQA commented Jun 7, 2022 via email

@VladislavKutsTAQA
Copy link
Author

VladislavKutsTAQA commented Jun 7, 2022 via email

@mbhoek
Copy link
Member

mbhoek commented Jun 7, 2022

You don't need to downgrade SpecFlow (I see your tests are async) but can you please try to downgrade only the plugin SolidToken.SpecFlow.DependencyInjection to 3.9.2?

@Tuzi555
Copy link

Tuzi555 commented Nov 9, 2022

I had the same issue and downgrading to version 3.9.2 of SolidToken.SpecFlow.DependencyInjection did the trick for me.

@mbhoek mbhoek added this to the Support SpecFlow v4 milestone Dec 2, 2022
@rjvega
Copy link

rjvega commented Feb 27, 2023

@VladislavKutsTAQA Thanks for your report. I notice you are using Specflow 3.10.2-beta which introduces async features for the first time. I haven't tested the plugin against this beta version yet.

However the exception occurs in a piece of code that was rewritten in the last version, so would you be so kind to try using v3.9.2 of the SpecFlow.DependencyInjection plugin and see if it still happens?

This worked for me. Thanks

@mbhoek
Copy link
Member

mbhoek commented Feb 28, 2023

Thanks for letting me know. I'll review the code and see if I can update it for the major version (v4).

@mbhoek
Copy link
Member

mbhoek commented Feb 14, 2024

Closing this issue because the plugin will be donated to Reqnroll.

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

No branches or pull requests

4 participants