SpecFlowOSS / SpecFlow.VS

The next version of the Visual Studio extension for SpecFlow
MIT License
39 stars 12 forks source link

Adding Azure.Identity project reference crashes the generic discovery connector #90

Open RemyBoyer opened 2 years ago

RemyBoyer commented 2 years ago

Used Visual Studio

Visual Studio 2022

Are the latest Visual Studio updates installed?

Yes

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

empty

Issue Description

Hello,

I'm running into issues with my main specflow project. I'm having both an error on the generic connector, and the "legacy" one, whatever this one is.

I have not been able to provide repro steps for the legacy connector (since I can't share my project), but I was able to do so for the Generic one, with minimal steps.

From what I understand, adding Azure.Identity adds System.Memory/4.5.4 (the nuget package) as dependency, and the connector loads this lib instead of the net6.0 one. Then later one it fails while trying to do System.Text.Json (de)serializations, since Span aren't available.

This is the output from Visual Studio:

Info: RunDiscovery: The binding discovery has failed with the generic discovery connector, but succeeded with the legacy connectors.
Info: ThenImportStepDefinitions: 1 step definitions discovered for project TestProject1

Here's the output when I launch the connector manually:

> & "C:\Program Files\dotnet\dotnet.exe" exec C:\Users\RemyBOYER\AppData\Local\Microsoft\VisualStudio\17.0_bbb23af8\Extensions\ifvzfqss.3pw\Connectors\Generic-net6.0\specflow-vs.dll discovery C:\Users\RemyBOYER\source\repos\ConsoleApp2\TestProject1\bin\Debug\net6.0\TestProject1.dll
DiscoveryOptions { DebugMode = False, AssemblyFile = C:\Users\RemyBOYER\source\repos\ConsoleApp2\TestProject1\bin\Debug\net6.0\TestProject1.dll, ConfigFile = , ConnectorFolder = C:\Users\RemyBOYER\AppData\Local\Microsoft\VisualStudio\17.0_bbb23af8\Extensions\ifvzfqss.3pw\Connectors\Generic-net6.0 }
Loading C:\Users\RemyBOYER\source\repos\ConsoleApp2\TestProject1\bin\Debug\net6.0\TestProject1.dll
TestProject1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null loaded
Microsoft.Extensions.DependencyModel.DependencyContext loaded
Loading System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Resolved with SpecFlowConnector.AssemblyLoading.NugetCacheAssemblyResolver
Loading System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Resolved with SpecFlowConnector.AssemblyLoading.NugetCacheAssemblyResolver
Loading System.Runtime.Loader, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Resolved with SpecFlowConnector.AssemblyLoading.NugetCacheAssemblyResolver
Loading System.Collections.Immutable, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Loading System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Resolved with SpecFlowConnector.AssemblyLoading.NugetCacheAssemblyResolver
Found compilation library:System.Text.Json, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Loading mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.MissingMethodException: Method not found: 'Void System.Text.Json.JsonSerializerOptions.set_DefaultIgnoreCondition(System.Text.Json.Serialization.JsonIgnoreCondition)'.
   at SpecFlowConnector.JsonSerialization.GetJsonSerializerSettings()
   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, IDictionary`2 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.<>c__DisplayClass0_0.<Execute>b__2(Object instance) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\ReflectionExecutor.cs:line 23
   at Some`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, Func`3 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.<>c__DisplayClass4_0.<Run>b__0(ConnectorOptions options) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\Runner.cs:line 29
   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.Runner.Run(String[] args, Func`3 testAssemblyFactory) in D:\a\1\s\Connectors\SpecFlow.VisualStudio.SpecFlowConnector.Generic\Runner.cs:line 26

My dotnet --info, if needed:

> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.301
 Commit:    43f9b18481

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.301\

Host (useful for support):
  Version: 6.0.6
  Commit:  7cca709db2

.NET SDKs installed:
  3.1.420 [C:\Program Files\dotnet\sdk]
  6.0.301 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

I can provide a repo if needed.

Steps to Reproduce

Use this csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
        <PackageReference Include="Azure.Identity" Version="1.6.0" />
        <PackageReference Include="NUnit" Version="3.13.3" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
    <PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
        <PackageReference Include="SpecFlow.NUnit.Runners" Version="3.9.74" />
  </ItemGroup>

</Project>

Add a feature. Compile.

The command I'm using to reproduce the issue:

& "C:\Program Files\dotnet\dotnet.exe" exec C:\Users\RemyBOYER\AppData\Local\Microsoft\VisualStudio\17.0_bbb23af8\Extensions\ifvzfqss.3pw\Connectors\Generic-net6.0\specflow-vs.dll discovery C:\Users\RemyBOYER\source\repos\ConsoleApp2\TestProject1\bin\Debug\net6.0\TestProject1.dll

Link to Repository Project

No response

icnocop commented 2 years ago

Adding the NuGet package System.Text.Json 6.0.5 to the test project resolved this issue for me.

The DefaultIgnoreCondition property was added to System.Text.Json 5. Source: https://devblogs.microsoft.com/dotnet/whats-next-for-system-text-json/