Azure / Azure/azure-functions-host

JsonProperty attributes not respected after upgrade to .NET Core 3.1 / Azure Functions v3

Open
#5,358 4 comments 7 reactions 0 assignees View on GitHub
3.x
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

I've just upgraded an Azure Function App from .NETCoreApp2.2 to .NETCoreApp3.1. When running the function **locally** (started from VS2019 16.4.0) I see that the `JsonProperty` attributes which are defined on my model classes are not respected.

```
public class Movie
{
[JsonProperty("title")]
public string Title { get; set; }

[JsonProperty("episode_id")]
public int Episode { get; set; }

[JsonProperty("release_date")]
public string ReleaseDate { get; set; }
}
```

#### Repro steps

Repo to repoduce: https://github.com/marcduiker/xebia-webinar-week-azurefunctions
Branch: `development-v3`
Do a `GET` to `http://localhost:7071/api/movies`

#### Expected behavior

The JsonProperty attributes are respected.
```
[
{
"title": "A New Hope",
"episode_id": 4,
"release_date": "1977-05-25"
},
...
]
```

#### Actual behavior

The JsonProperty attributes are **not** respected. No errors are shown.

```
[
{
"title": "A New Hope",
"episode": 0,
"releaseDate": null
},
...
]
```

#### Workaround:
@fabiocav [mentioned](https://twitter.com/codesapien/status/1204187805393440768) that a workaround would be to set the App Setting `FUNCTIONS_V2_COMPATIBILITY_MODE=true`. This indeed works. 👍

#### Related information

Azure Functions Core Tools (3.0.1975 Commit hash: faab364ffc9b9bbaaac212d061691663624d8d4)
Function Runtime Version: 3.0.12930.0

```


netcoreapp3.1
v3








PreserveNewest


PreserveNewest
Never

```

Contributor guide

Open the contributing guide

Research direction

Use the linked xebia-webinar-week-azurefunctions repository on the development-v3 branch and run the local GET at /api/movies. Compare serialization with and without FUNCTIONS_V2_COMPATIBILITY_MODE=true, then trace the Azure Functions host behavior responsible for JsonProperty handling; done means the expected title, episode_id, and release_date names appear without the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
api, backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.