SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

Error Loading Assembly when using Specflow.Autofac (Could not load file or assembly 'SpecFlow.Autofac.SpecFlowPlugin)

Open victorperez2911 opened this issue 3 years ago • 2 comments

SpecFlow Version

3.9.7

Which test runner are you using?

SpecFlow+ Runner

Test Runner Version Number

3.9.7

.NET Implementation

.NET 5.0

Project Format of the SpecFlow project

Classic project format using <PackageReference> tags

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

No response

Issue Description

  1. Normalizar notas com status de processamento pendente Duração: 96 ms

    Mensagem: Exception has been thrown by the target of an invocation. -> Could not load file or assembly 'SpecFlow.Autofac.SpecFlowPlugin, Version=3.9.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'. Could not find or load a specific file. (0x80131621)

    Rastreamento de Pilha: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'SpecFlow.Autofac.SpecFlowPlugin, Version=3.9.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'. Could not find or load a specific file. (0x80131621) File name: 'SpecFlow.Autofac.SpecFlowPlugin, Version=3.9.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41' ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg) CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable) CustomAttribute.IsDefined(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit) RuntimeMethodInfo.IsDefined(Type attributeType, Boolean inherit) Attribute.IsDefined(MemberInfo element, Type attributeType, Boolean inherit) Attribute.IsDefined(MemberInfo element, Type attributeType) <>c.<FindCreateScenarioContainerBuilder>b__4_0(MethodInfo m) WhereArrayIterator1.MoveNext() ContainerBuilderFinder.FindCreateScenarioContainerBuilder() Lazy1.ViaFactory(LazyThreadSafetyMode mode) Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) Lazy1.CreateValue() Lazy1.get_Value() ContainerBuilderFinder.GetCreateScenarioContainerBuilder() <>c__DisplayClass1_0.<Initialize>b__2() --- End of inner exception stack trace --- RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) Delegate.DynamicInvokeImpl(Object[] args) Delegate.DynamicInvoke(Object[] args) ObjectContainer.InvokeFactoryDelegate(Delegate factoryDelegate, ResolutionList resolutionPath, RegistrationKey keyToResolve) <>c__DisplayClass3_0.<ResolvePerContext>b__1() RegistrationWithStrategy.ExecuteWithLock(Object lockObject, Func1 getter, Func1 factory, ResolutionList resolutionPath) FactoryRegistration.ResolvePerContext(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath) RegistrationWithStrategy.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath) ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath) ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name) ObjectContainer.Resolve(Type typeToResolve, String name) ObjectContainer.Resolve[T](String name) ObjectContainer.ResolveT AutofacTestObjectResolver.ResolveBindingInstance(Type bindingType, IObjectContainer scenarioContainer) lambda_method124(Closure , IContextManager ) BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) linha 73 TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments, TimeSpan& duration) linha 618 RunnerTestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments, TimeSpan& duration) TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance) linha 531 TestExecutionEngine.OnAfterLastStep() linha 286 RunnerTestExecutionEngine.OnAfterLastStep() TestRunner.CollectScenarioErrors() linha 59 NormalizacaoNFeFeature.ScenarioCleanup() NormalizacaoNFeFeature.NormalizarNotasComStatusDeProcessamentoPendente() linha 7 StaticOrInstanceMethodExecutor.ExecuteInternal(ITestThreadExecutionContext testThreadExecutionContext) StaticOrInstanceMethodExecutor.Execute(ITestThreadExecutionContext testThreadExecutionContext) TestNodeTask.Execute()

Steps to Reproduce

  1. Create a new Project with Specflow default Template.

  2. Create a Empty Scenario.

  3. Add Specflow.Autofac Nuget Package.

  4. Add a class with a static method with attribute [ScenarioDependencies]

public class Startup
    {
        [ScenarioDependencies]
        public static ContainerBuilder CreateContainerBuilder()
        {
            // create container with the runtime dependencies
            //var builder = AddServicesForTests();
            var builder = new ContainerBuilder();

            //TODO: add customizations, stubs required for testing

            //builder.RegisterAssemblyTypes(typeof(Startup).Assembly).SingleInstance();
            
            //builder.RegisterTypes(typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))).ToArray()).SingleInstance();

            builder.RegisterTypes(typeof(Startup).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))).ToArray()).SingleInstance();

            return builder;
        }
  1. Run Test in VS2019

Link to Repro Project

No response

victorperez2911 avatar Sep 15 '21 21:09 victorperez2911

The problem only occurs in version 3.9.22 of the SpecFlow.AutoFac package, with version 3.9.8 working.

victorperez2911 avatar Sep 16 '21 19:09 victorperez2911

That is strange, as there are no changes in these versions that would do anything with the DI support. After updating to 3.9.22 could you delete your obj/bin folder and build again?

SabotageAndi avatar Sep 17 '21 11:09 SabotageAndi