Lambda Test Tool returns Error deserializing the input JSON to type APIGatewayProxyRequest with System.Text.Json v7
See original GitHub issueHi,
I’m working with solution on .net6 with lambda project, and AWS Toolkit for Visual Studio.
I faced with issue testing lambda locally using Lambda Test Tool.
In case if solution has a reference to System.Text.Json version 7 and above.
When I Execute Function from Mock Lambda Test Tool I get following error: “Error deserializing the input JSON to type APIGatewayProxyRequest”, see full error log below, interesting part goes under the Inner 2 Exception: “Operation is not supported on this platform”.
System.Exception: Error deserializing the input JSON to type APIGatewayProxyRequest
at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.BuildParameters(ExecutionRequest request, ILambdaContext context) in C:\build\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 255
at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.ExecuteAsync(ExecutionRequest request) in C:\build\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 65
---------------- Inner 1 Exception ------------
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
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 Amazon.Lambda.TestTool.Runtime.LambdaExecutor.BuildParameters(ExecutionRequest request, ILambdaContext context) in C:\build\Tools\LambdaTestTool\src\Amazon.Lambda.TestTool\Runtime\LambdaExecutor.cs:line 225
---------------- Inner 2 Exception ------------
Amazon.Lambda.Serialization.SystemTextJson.JsonSerializerException: Error converting the Lambda event JSON payload to type Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest: Operation is not supported on this platform.
at Amazon.Lambda.Serialization.SystemTextJson.AbstractLambdaJsonSerializer.Deserialize[T](Stream requestStream)
---------------- Inner 3 Exception ------------
System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Text.Encodings.Web.OptimizedInboxTextEncoder.AllowedAsciiCodePoints.get_AsVector()
at System.Text.Encodings.Web.OptimizedInboxTextEncoder.GetIndexOfFirstByteToEncodeSsse3(Byte* pData, UIntPtr lengthInBytes)
at System.Text.Encodings.Web.OptimizedInboxTextEncoder.GetIndexOfFirstByteToEncode(ReadOnlySpan`1 data)
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.CacheNameAsUtf8BytesAndEscapedNameSection()
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.InitializePropertyCache()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureLocked|143_0()
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Boolean resolveIfMutable)
at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
at System.Text.Json.JsonSerializer.Deserialize[TValue](ReadOnlySpan`1 utf8Json, JsonSerializerOptions options)
at Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer.InternalDeserialize[T](Byte[] utf8Json)
at Amazon.Lambda.Serialization.SystemTextJson.AbstractLambdaJsonSerializer.Deserialize[T](Stream requestStream)
Once I downgraded System.Text.Json package to version 6 in my solution, I’m able to invoke lambda from Lambda Test Tool.
Moreover with System.Text.Json package version 7 I was able to invoke my function from AWS Console, meaning it does able to deserialize input to APIGatewayProxyRequest, so the issue seems to be in Mock Lambda Test Tool itself.
Expected Behavior
System.Text.Json version 7+ should not cause deserializing errors using AWS .NET Core 6.0 Mock Lambda Test Tool
Current Behavior
System.Text.Json version 7+ causes deserializing errors using AWS .NET Core 6.0 Mock Lambda Test Tool
Reproduction Steps
You can use any Lambda .net6 project, include System.Text.Json v7+ package in project.
Also add AWS Toolkit for Visual Studio (if using that IDE)
Test your lambda with Mock Lambda Test Tool
Execute Function from Mock Lambda Test Tool, see deserializing error in response.
Possible Solution
No response
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
Packages in solution:
Amazon.Lambda.Corev2.1.0Amazon.Lambda.Serialization.SystemTextJsonv2.3.1Amazon.Lambda.APIGatewayEventsv2.6.0System.Text.Jsonv7.0.2
Targeted .NET Platform
.NET 6
Operating System and version
Windows 10
Issue Analytics
- State:
- Created 4 months ago
- Comments:9 (5 by maintainers)
Top Related StackOverflow Question
Reproducible using customer’s solution. However, adding
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>in.csprojfile resolves the issue. This copies version7.0.xxx.xxxxofSystem.Text.JsonandSystem.Text.Encodings.Webtobin\Debug\net6.0while debugging using Lambda Test Tool.Per CopyLocalLockFileAssemblies,
property is useful for plugin projects that have dependencies on other libraries. If you set this property to true, any NuGet package dependencies are copied to the output directory. That means you can use the output of dotnet build to run your plugin on any machine.⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.