Skip to content

JsonPropertyInfo.AttributeProvider is null when using JsonSerializerContext #96532

Answered by eiriktsarpalis
Dean-NC asked this question in General
Discussion options

You must be logged in to vote

I'm guessing it's because source-gen knows it doesn't need custom attributes it doesn't know about so it doesn't bother letting us access AttributeProvider, or is something else wrong?

That's correct, the source generator doesn't need those so it also doesn't attempt to populate them. The source generator could theoretically generate code that queries the relevant MemberInfo and populates the AttributeProvider property, however that isn't pay-for-play and it would negatively impact startup time for applications that don't apply contract customization.

My recommendation would be to insert an equivalent querying logic in your customization code, roughly:

property.AttributeProvider ??= typ…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Dean-NC
Comment options

@eiriktsarpalis
Comment options

Answer selected by Dean-NC
Comment options

You must be logged in to vote
1 reply
@eiriktsarpalis
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Text.Json untriaged New issue has not been triaged by the area owner
3 participants
Converted from issue

This discussion was converted from issue #96387 on January 05, 2024 09:09.