aws / aws/aws-lambda-dotnet

JsonSerializer.Deserialize<T> returns invalid object when called by TypeConverter within AWS Lambda Test Tool

Offen
#1,453 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug module/lambda-test-tool p2 queued
Vorherrschende Sprache
C#
Sterne
1.7k
Forks
503
Ø Merge
1 T. 18 Std.
Gemergte PRs (30 T.)
21

Beschreibung

### Describe the bug

When I'm running some code in the test tool, I come across an issue, when System.Text.Json.JsonSerializer.Deserialize returns different results depending on whether it's being called from the top level or from a System.ComponentModel.TypeConverter method.

This is best illustrated with code (see attachment)

[lambda-test-tool.zip](https://github.com/aws/aws-lambda-dotnet/files/10959736/lambda-test-tool.zip)

Run:

```
dotnet tool restore
dotnet build
dotnet dotnet-lambda-test-tool-6.0 --no-ui --function-handler Lambda::Main.Lambda::Handler --pause-exit false
```

Output:

```
AWS .NET Core 6.0 Mock Lambda Test Tool (0.12.7)
Loaded local Lambda runtime from project output /home/alex.bolenok/Projects/lambda-test-tool/bin/Debug/net6.0
Executing Lambda function without web interface
... Using function handler Lambda::Main.Lambda::Handler
... No payload configured. If a payload is required set the --payload switch to a file path or a JSON document.
... Setting AWS_PROFILE environment variable to default.
... No default AWS region configured. The --region switch can be used to configure an AWS Region.
Captured Log information:
test
True
Main.S3Bucket
Main.S3Bucket
>>>> False <<<<

Request executed successfully
Response:
```

This issue seems to be specific to the test tool (when I run this code in an actual Lambda, or in a console app, it works as expected).

### Expected Behavior

`TypeDescriptor.GetConverter(typeof T).ConvertFrom` and `JsonSerializer.Deserialize` both return objects of the same type `T`.

### Current Behavior

`TypeDescriptor.GetConverter(typeof T).ConvertFrom` and `JsonSerializer.Deserialize` return objects of different types.

### Reproduction Steps

Run:

```
dotnet tool restore
dotnet build
dotnet dotnet-lambda-test-tool-6.0 --no-ui --function-handler Lambda::Main.Lambda::Handler --pause-exit false
```

Output:

```
AWS .NET Core 6.0 Mock Lambda Test Tool (0.12.7)
Loaded local Lambda runtime from project output /home/alex.bolenok/Projects/lambda-test-tool/bin/Debug/net6.0
Executing Lambda function without web interface
... Using function handler Lambda::Main.Lambda::Handler
... No payload configured. If a payload is required set the --payload switch to a file path or a JSON document.
... Setting AWS_PROFILE environment variable to default.
... No default AWS region configured. The --region switch can be used to configure an AWS Region.
Captured Log information:
test
True
Main.S3Bucket
Main.S3Bucket
>>>> False <<<<

Request executed successfully
Response:
```

### Possible Solution

There is something weird in the way the test tool calles the framework methods. The actual lambda runtime works fine.

### Additional Information/Context

_No response_

### AWS .NET SDK and/or Package version used

```
{
"version": 1,
"isRoot": true,
"tools": {
"amazon.lambda.testtool-6.0": {
"version": "0.12.7",
"commands": [
"dotnet-lambda-test-tool-6.0"
]
}
}
}
```

```



```

### Targeted .NET Platform

.NET 6

### Operating System and version

Amazon Linux

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Extract lambda-test-tool.zip and run the listed dotnet tool restore, build, and dotnet-lambda-test-tool-6.0 commands with the supplied handler. Start by comparing the top-level and TypeConverter calls in the reproduction; done means both TypeDescriptor.GetConverter(typeof T).ConvertFrom and JsonSerializer.Deserialize return the same type T under the test tool.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
aws, csharp
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.