SpecFlow.VS icon indicating copy to clipboard operation
SpecFlow.VS copied to clipboard

Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1<Byte>)'.

Open stegander opened this issue 3 years ago • 0 comments

Used Visual Studio

Visual Studio 2022

Are the latest Visual Studio updates installed?

Yes

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

{
  "language": {
    "feature": "sv"
  },
  "generator": {
     "addNonParallelizableMarkerForTags": [ "NoneParallel" ]
  }
}

Issue Description

Info: OnActivityStarted: Starting Visual Studio Extension...
Info: CreateProjectScope: Initializing project: SpecFlowTests
Info: StartRetryInitializeTimer: Project settings not available yet, retry in 5 seconds...
Info: OnSettingsInitialized: Project settings initialized: .NETCoreApp,Version=v6.0,SpecFlow:3.9.74
Warning: AndDiscoveryProviderSucceed: Error during binding discovery. 
Command executed:
  C:\tfs\git\LAB.SpecFlowPluginExemple\SpecFlowTests\bin\Debug\net6.0> C:\Program Files\dotnet\dotnet.exe exec C:\Users\******\AppData\Local\Microsoft\VisualStudio\17.0_f5e051c6\Extensions\ppz3rzme.oda\Connectors\Generic-net6.0\specflow-vs.dll discovery C:\tfs\git\LAB.SpecFlowPluginExemple\SpecFlowTests\bin\Debug\net6.0\SpecFlowTests.dll C:\tfs\git\LAB.SpecFlowPluginExemple\SpecFlowTests\specflow.json
Exit code: 4
Message: 
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`1<Byte>)'.
   at System.Text.Json.JsonWriterHelper.NeedsEscaping(ReadOnlySpan`1 value, JavaScriptEncoder encoder)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.DeterminePropertyName()
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.GetPolicies(Nullable`1 ignoreCondition, Nullable`1 declaringTypeNumberHandling)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.Initialize(Type parentClassType, Type declaredPropertyType, Type runtimePropertyType, ConverterStrategy runtimeClassType, MemberInfo memberInfo, Boolean isVirtual, JsonConverter converter, Nullable`1 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, Nullable`1 parentTypeNumberHandling, Nullable`1 ignoreCondition)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.AddProperty(MemberInfo memberInfo, Type memberType, Type parentClassType, Boolean isVirtual, Nullable`1 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, 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
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, Func`2 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.

Steps to Reproduce

We get this after adding a dependency to RazorLight in our project.

<PackageReference Include="RazorLight" Version="2.1.0" />

And we add this code:

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace RazorLightUser.Extensions;

public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddHtmlGenerator(this IServiceCollection services, IConfiguration configuration)
    {
        // If commented out, we get no SpecFlow error
        services.AddRazorPages();
            
        return services;
    }
}

Link to Repository Project

No response

stegander avatar Aug 23 '22 06:08 stegander