Open kwaazaar opened 2 years ago
Me too cannot discover project bindings.
Exit code: 4
Message:
Exception in:SpecFlow.VisualStudio.SpecFlowConnector.Discovery.V38.SpecFlowV38Discoverer
Error: Exception has been thrown by the target of an invocation. -> Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.Extensions.Hosting.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
Exception: System.Reflection.TargetInvocationException->System.Reflection.ReflectionTypeLoadException
StackTrace:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at TechTalk.SpecFlow.Bindings.Discovery.RuntimeBindingRegistryBuilder.BuildBindingsFromAssembly(Assembly assembly)
at TechTalk.SpecFlow.TestRunnerManager.BuildBindingRegistry(IEnumerable1 bindingAssemblies)
at TechTalk.SpecFlow.TestRunnerManager.InitializeBindingRegistry(ITestRunner testRunner)
at TechTalk.SpecFlow.TestRunnerManager.CreateTestRunner(Int32 threadId)
at SpecFlow.VisualStudio.SpecFlowConnector.Discovery.SpecFlowV3BaseDiscoverer.GetBindingRegistry(Assembly testAssembly, String configFilePath) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.V3\Discovery\SpecFlowV3BaseDiscoverer.cs:line 28
at SpecFlow.VisualStudio.SpecFlowConnector.Discovery.BaseDiscoverer.DiscoverInternal(Assembly testAssembly, String testAssemblyPath, String configFilePath) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector\Discovery\BaseDiscoverer.cs:line 31
at SpecFlow.VisualStudio.SpecFlowConnector.Discovery.BaseDiscoverer.Discover(Assembly testAssembly, String testAssemblyPath, String configFilePath) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector\Discovery\BaseDiscoverer.cs:line 21
at SpecFlow.VisualStudio.SpecFlowConnector.Discovery.VersionSelectorDiscoverer.Discover(Assembly testAssembly, String testAssemblyPath, String configFilePath) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.V3\Discovery\VersionSelectorDiscoverer.cs:line 25
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at SpecFlow.VisualStudio.SpecFlowConnector.ReflectionExtensions.ReflectionCallMethod[T](Object obj, String methodName, Type[] parameterTypes, Object[] args) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector\ReflectionExtensions.cs:line 31
at SpecFlow.VisualStudio.SpecFlowConnector.Discovery.ReflectionSpecFlowDiscoverer.Discover(Assembly testAssembly, String testAssemblyPath, String configFilePath) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.V3\Discovery\ReflectionSpecFlowDiscoverer.cs:line 21
at SpecFlow.VisualStudio.SpecFlowConnector.Discovery.DiscoveryProcessor.Process() in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.V2\Discovery\DiscoveryProcessor.cs:line 26
at SpecFlow.VisualStudio.SpecFlowConnector.DiscoveryCommand.Execute(String[] commandArgs) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector\DiscoveryCommand.cs:line 17
at SpecFlow.VisualStudio.SpecFlowConnector.ConsoleRunner.EntryPoint(String[] args) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector\ConsoleRunner.cs:line 23
Warning: InvokeDiscovery: The project bindings (e.g. step definitions) could not be discovered. Navigation, step completion and other features are disabled.
Please check the error message above and report to https://github.com/SpecFlowOSS/SpecFlow.VS/issues if you cannot fix.
In my case the problem was using Microsoft.NET.Sdk.Web
in the test project. After I changed it to Microsoft.NET.Sdk
bindings started working again.
@kwaazaar @nawijesi I need some help to reproduce these issues locally. Can you share me your csproj content?
Hi, I have the same problem as described in this issue. Is there any progress regarding this bug? We are using Visual Studio 2022 and SpecFlow extension 2021.4.5.18546. Our test project is a Microsoft.NET.Sdk.Web.
I plan to fix this in the next release. Please help me to reproduce this issue locally on my laptop. The best would be if you can create and share a repo where the issue exists. Or I can give you write access to our investigation repo, where you can commit a sample. If this doesn't work, then I need the csproj content of your test project
It took me a lot of digging in dependencies to figure out what caused the problem. It seems to be when I add
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
I have made a test solution with one ASP.net Core Web App and one SpecFlow Project. The SpecFlow project has a project reference to the ASP.net Core Web App.
.csproj for the ASP.net Core Web App (named SpecFlowPluginExemple):
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
</ItemGroup>
</Project>
.csproj for the SpecFlow project:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.40" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Drivers\" />
<Folder Include="Support\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SpecFlowPluginExemple\SpecFlowPluginExemple.csproj" />
</ItemGroup>
</Project>
Note: Sdk for the SpecFlow project must be changed to "Microsoft.NET.Sdk.Web"
I hope this can help you reproduce this locally.
And since 'Microsoft.AspNetCore.Mvc.Core' can be a dependency from another Nuget package as well, it's impossible to work around this.
Dependencies can be found in ~/
@patiqs were you able to reproduce the problem locally or can I help you in any way?
@stegander Yes. Thank you for identifying the issue. I can reproduce this way
In the past few weeks I have worked on a refactored connector. We want to publish it in the upcomming weeks, but here is a beta version if you want to test: https://github.com/SpecFlowOSS/Investigation/blob/main/SpecFlow.VisualStudio.Package.vsix
In the past few weeks I have worked on a refactored connector. We want to publish it in the upcomming weeks, but here is a beta version if you want to test: https://github.com/SpecFlowOSS/Investigation/blob/main/SpecFlow.VisualStudio.Package.vsix
I get 404 when I try to get the beta version.
Do you have any update on when it will be released?
Any updates on this?
Is this issue already fixed? It has been a while since there was an update about this.
@patiqs @gasparnagy any update on this one? I saw that the PR was not in the new release.
I uninstalled and reinstalled the SpecFlow VS 2022 extension. That removed this error ("The project bindings (e.g. step definitions) could not be discovered"), and left me with:
Info: OnActivityStarted: Starting Visual Studio Extension... Info: CreateProjectScope: Initializing project: Info: OnSettingsInitialized: Project settings initialized: .NETCoreApp,Version=v6.0,SpecFlow:3.9.58 Info: AndBindingSourceIsValid: Test assembly not found. Please build the project to enable the SpecFlow Visual Studio Extension features.
Then I built each project inside my solution, separaterly. Then I could built it all together and have it working. This worked for one of the projects inside the solution, but when opening a feature file in another project inside the same solution, the original error was back.
@klarahovstadius Hello. I think you case is a different problem. Could you please create a new issue for that?
@klarahovstadius Hello. I think you case is a different problem. Could you please create a new issue for that?
Absolutely!
Now in the last version it’s working for us! Thank you! =)
It is still not working for us. We now have a different error though. This is the error we see now:
Info: OnActivityStarted: Starting Visual Studio Extension... Info: CreateProjectScope: Initializing project: ***.***.Core.Api.Specs Info: OnSettingsInitialized: Project settings initialized: .NETCoreApp,Version=v6.0,SpecFlow:3.9.74 Warning: AndDiscoveryProviderSucceed: Error during binding discovery. Command executed: C:\Data\Projects\***\***\***.***.Core.Api.Specs\bin\Debug\net6.0> C:\Program Files\dotnet\dotnet.exe exec C:\Users\***\AppData\Local\Microsoft\VisualStudio\17.0_d19657c6\Extensions\04jeatzf.mw5\Connectors\Generic-net6.0\specflow-vs.dll discovery C:\Data\Projects\***\***\***.***.Core.Api.Specs\bin\Debug\net6.0\***.***.Core.Api.Specs.dll C:\Data\Projects\***\***\***.***.Core.Api.Specs\specflow.json Exit code: 4 Message: System.InvalidOperationException: Cannot find reference assembly 'System.Core.dll' file for package System.Core at Microsoft.Extensions.DependencyModel.Resolution.ReferenceAssemblyPathResolver.TryResolveAssemblyPaths(CompilationLibrary library, List
1 assemblies)
at SpecFlowConnector.AssemblyLoading.RuntimeCompositeCompilationAssemblyResolver.TryResolveAssemblyPaths(CompilationLibrary library, List1 assemblies) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\AssemblyLoading\RuntimeCompositeCompilationAssemblyResolver.cs:line 19 System.InvalidOperationException: Cannot find reference assembly 'System.Core.dll' file for package System.Core at Microsoft.Extensions.DependencyModel.Resolution.ReferenceAssemblyPathResolver.TryResolveAssemblyPaths(CompilationLibrary library, List
1 assemblies)
at SpecFlowConnector.AssemblyLoading.RuntimeCompositeCompilationAssemblyResolver.TryResolveAssemblyPaths(CompilationLibrary library, List1 assemblies) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\AssemblyLoading\RuntimeCompositeCompilationAssemblyResolver.cs:line 19 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MissingMethodException: Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan
11 value, JavaScriptEncoder encoder) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.DeterminePropertyName() at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.GetPolicies(Nullable
1 ignoreCondition, Nullable1 declaringTypeNumberHandling) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo
1.Initialize(Type parentClassType, Type declaredPropertyType, Type runtimePropertyType, ConverterStrategy runtimeClassType, MemberInfo memberInfo, Boolean isVirtual, JsonConverter converter, Nullable1 ignoreCondition, Nullable
1 parentTypeNumberHandling, JsonSerializerOptions options)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.CreateProperty(Type declaredPropertyType, Type runtimePropertyType, MemberInfo memberInfo, Type parentClassType, Boolean isVirtual, JsonConverter converter, JsonSerializerOptions options, Nullable1 parentTypeNumberHandling, Nullable
1 ignoreCondition)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.AddProperty(MemberInfo memberInfo, Type memberType, Type parentClassType, Boolean isVirtual, Nullable1 parentTypeNumberHandling, JsonSerializerOptions options) at System.Text.Json.Serialization.Metadata.JsonTypeInfo..ctor(Type type, JsonConverter converter, Type runtimeType, JsonSerializerOptions options) at System.Text.Json.Serialization.Metadata.JsonTypeInfo..ctor(Type type, JsonSerializerOptions options) at System.Text.Json.JsonSerializerOptions.<InitializeForReflectionSerializer>g__CreateJsonTypeInfo|112_0(Type type, JsonSerializerOptions options) at System.Text.Json.JsonSerializerOptions.GetClassFromContextOrCreate(Type type) at System.Text.Json.JsonSerializerOptions.GetOrAddClass(Type type) at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type runtimeType) at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options) at SpecFlowConnector.JsonSerialization.SerializeObject(Object obj) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\JsonSerialization.cs:line 15 at FunctionalExtensions.Map[TSource,TResult](TSource this, Func
2 fn) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\NetExtensions\FunctionalExtensions.cs:line 5
at SpecFlowConnector.ReflectionExecutor.Execute(String optionsJson, Assembly testAssembly, AssemblyLoadContext assemblyLoadContext, IDictionary2 analyticsProperties) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\ReflectionExecutor.cs:line 67 --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Span
1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at SpecFlowConnector.ReflectionExtensions.ReflectionCallMethod[T](Object obj, String methodName, Type[] parameterTypes, Object[] args) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\NetExtensions\ReflectionExtensions.cs:line 26
at SpecFlowConnector.ReflectionExtensions.ReflectionCallMethod[T](Object obj, String methodName, Object[] args) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\NetExtensions\ReflectionExtensions.cs:line 7
at SpecFlowConnector.ReflectionExecutor.<>cDisplayClass0_0.1.Map[TResult](Func
2 map) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\NetExtensions\Optional\Some.cs:line 26
at SpecFlowConnector.ReflectionExecutor.Execute(DiscoveryOptions options, Func3 testAssemblyFactory, ILogger _log, IAnalyticsContainer analytics) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\ReflectionExecutor.cs:line 21 at SpecFlowConnector.Runner.ExecuteDiscovery(DiscoveryOptions options, Func
3 testAssemblyFactory) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\Runner.cs:line 44
at SpecFlowConnector.Runner.<>c2 fn) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\NetExtensions\FunctionalExtensions.cs:line 5 at SpecFlowConnector.Runner.Run(String[] args, Func
3 testAssemblyFactory) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\Runner.cs:line 26
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: D. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at SpecFlow.VisualStudio.Connectors.OutProcSpecFlowConnector.Deserialize(RunProcessResult result, Func2 formatErrorMessage) Warning: AndDiscoveryProviderSucceed: The project bindings (e.g. step definitions) could not be discovered. Navigation, step completion and other features are disabled. Please check the error message above and report to https://github.com/SpecFlowOSS/SpecFlow.VS/issues if you cannot fix.
Any ideas how to fix this?
I use SpecFlow for an integrationtest on my webservice. These projects were not supported officially before, but by changing the sdk type afterwards, the project worked fine in VS2019 and targeting .NET 5. Now I run VS2022 and target .NET 6 and get this error. (the reference to old ASP.NET 2.2 libraries is a dependency of a referenced nuget package and was there before too)