Lambda Test Tool returns Error deserializing the input JSON to type APIGatewayProxyRequest with System.Text.Json v7

See original GitHub issue

Hi, 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.Core v2.1.0
  • Amazon.Lambda.Serialization.SystemTextJson v2.3.1
  • Amazon.Lambda.APIGatewayEvents v2.6.0
  • System.Text.Json v7.0.2

Targeted .NET Platform

.NET 6

Operating System and version

Windows 10

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ashishdhingracommented, Jun 2, 2023

Hi @ashishdhingra,

I’ve attached a lambda solution example in which I’m able to reproduce the issue. Please take a look.

lambdatest_service.zip

Thanks!

Reproducible using customer’s solution. However, adding <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> in .csproj file resolves the issue. This copies version 7.0.xxx.xxxx of System.Text.Json and System.Text.Encodings.Web to bin\Debug\net6.0 while 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.

0reactions
github-actions[bot]commented, Jun 7, 2023

⚠️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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Hello World C# Lambda function returning Json error
I get the error: System.Exception: Error deserializing the input JSON to type String at Amazon.Lambda.TestTool.Runtime.LambdaExecutor.
Read more >
Error deserializing the input JSON to type String at Amazon
Created a new solution with Visual Studio using AWS Toolkit templates. Making no changes to the generated solution I execute the project ...
Read more >
AWS Lambda function errors in C# - ...
When your code raises an error, Lambda generates a JSON representation of the error. This error document appears in the invocation log and,...
Read more >
Error converting the Lambda event JSON payload to type ...
I had a Lambda function that took a string as its input. public Item FunctionHandler(string inventoryId, ILambdaContext context) ...
Read more >
Writing list<dynamic> to json file via system.text.json : r/dotnet
I have a very complex object that is currently in a List object and would like to write this out to json file....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found