JsonPropertyInfo.AttributeProvider
is null when using JsonSerializerContext
#96532
-
I use JSON source gen. I also need to use a modifier, and if the property has a certain custom attribute then change
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 Thanks much. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
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 My recommendation would be to insert an equivalent querying logic in your customization code, roughly: property.AttributeProvider ??= typeInfo.Type.GetMember(property.Name, MemberTypes.Property | MemberTypes.Field, <relevant binding flags>); |
Beta Was this translation helpful? Give feedback.
-
neither works with NativeAOT, do u know how to solve this? seems
in code:
btw, is this legal???
but after i compiled this with NativeAot, it does work, so do the Warnings really matter? |
Beta Was this translation helpful? Give feedback.
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 theAttributeProvider
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…