Azure-functions-host: JsonProperty attributes not respected after upgrade to .NET Core 3.1 / Azure Functions v3

Created on 10 Dec 2019  路  2Comments  路  Source: Azure/azure-functions-host

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 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

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>
3.x

Most helpful comment

@fabiocav & team -- Visual Studio and func core tools are still on 3.0.12930.0. Developing locally, JsonProperty is not respected. Then upon release, it suddenly is. This is causing big challenges in the development process. Any idea when VS or func core tools will be updated??

All 2 comments

@fabiocav & team -- Visual Studio and func core tools are still on 3.0.12930.0. Developing locally, JsonProperty is not respected. Then upon release, it suddenly is. This is causing big challenges in the development process. Any idea when VS or func core tools will be updated??

@fabiocav & team -- any information or updates available here? VS 16.4.4 was just put out today and it still has 3.0.12930.0. This makes it very challenging to develop solutions in VS that run the same as they do in Azure, as Json serialization works differently.

Was this page helpful?
0 / 5 - 0 ratings