SpecFlow
SpecFlow copied to clipboard
Error Loading Assembly when using Specflow.Autofac (Could not load file or assembly 'SpecFlow.Autofac.SpecFlowPlugin)
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
-
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, ListBuilder
1& 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) WhereArrayIterator
1.MoveNext() ContainerBuilderFinder.FindCreateScenarioContainerBuilder() Lazy1.ViaFactory(LazyThreadSafetyMode mode) Lazy
1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) Lazy1.CreateValue() Lazy
1.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, Func
1 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
-
Create a new Project with Specflow default Template.
-
Create a Empty Scenario.
-
Add Specflow.Autofac Nuget Package.
-
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;
}
- Run Test in VS2019
Link to Repro Project
No response
The problem only occurs in version 3.9.22 of the SpecFlow.AutoFac package, with version 3.9.8 working.
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?