Skip to content

System.Text.Json no longer disregards members with JsonConverterAttribute and JsonIgnoreAttribute #58469

Closed

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work]
Please see the attached csproj file.

It is a very basic Blazor project that utilizes a Syncfusion control. This control works in . NET6 preview-7 but throws the following exception in rc1 and the rc2 build available today:

System.InvalidOperationException: The converter specified on 'Syncfusion.Blazor.Grids.GridColumn.EditTemplate' does not derive from JsonConverter or have a public parameterless constructor.
   at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializationConverterOnAttributeInvalid(Type classType, MemberInfo memberInfo)
   at System.Text.Json.JsonSerializerOptions.GetConverterFromAttribute(JsonConverterAttribute converterAttribute, Type typeToConvert, Type classTypeAttributeIsOn, MemberInfo memberInfo)
   at System.Text.Json.JsonSerializerOptions.DetermineConverter(Type parentClassType, Type runtimePropertyType, MemberInfo memberInfo)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.GetConverter(Type type, Type parentClassType, MemberInfo memberInfo, Type& runtimeType, JsonSerializerOptions options)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.AddProperty(MemberInfo memberInfo, Type memberType, Type parentClassType, Boolean isVirtual, Nullable`1 parentTypeNumberHandling, JsonSerializerOptions options)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.CacheMember(Type declaringType, Type memberType, MemberInfo memberInfo, Boolean isVirtual, Nullable`1 typeNumberHandling, Boolean& propertyOrderSpecified, Dictionary`2& ignoredMembers)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.. ctor(Type type, JsonConverter converter, Type runtimeType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializerOptions. <InitializeForReflectionSerializer>g__CreateJsonTypeInfo|112_0(Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializerOptions.GetClassFromContextOrCreate(Type type)
   at System.Text.Json.JsonSerializerOptions.GetOrAddClass(Type type)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.get_ElementTypeInfo()
   at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryWrite(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWriteAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.DictionaryDefaultConverter`3.OnWriteResume(Utf8JsonWriter writer, TDictionary value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonDictionaryConverter`3.OnTryWrite(Utf8JsonWriter writer, TDictionary dictionary, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.JsonSerializer.WriteUsingSerializer[TValue](Utf8JsonWriter writer, TValue& value, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.WriteStringUsingSerializer[TValue](TValue& value, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
   at Syncfusion.Blazor.Grids.SfGrid`1.SerializeModel(SfGrid`1 comp)
   at Syncfusion.Blazor.Grids.SfGrid`1.OnAfterRenderAsync(Boolean firstRender)

Again this works on 6.0.100-preview.7.21379.14 but not on 6.0.100-rc.1.21416.1 or 6.0.100-rc.2.21420.30.

I have attached a recording of the exception occurring.


Original Comments

Feedback Bot on 8/23/2021, 01:57 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

DragonSpark on 8/23/2021, 04:14 AM:

FWIW this is also being tracked on Syncfusion’s side here:
https://www.syncfusion.com/feedback/28117/serialization-exception-throws-in-sfgrid-while-upgrading-to-latest-net-version


Original Solutions

(no solutions)

Activity

  1. ghost added
    untriaged
    on Aug 31, 2021
  2. eiriktsarpalis commented on Sep 7, 2021

    @eiriktsarpalis
    Member

    The exception message:

    The converter specified on 'Syncfusion.Blazor.Grids.GridColumn.EditTemplate' does not derive from JsonConverter or have a public parameterless constructor.

    Seems to provide a clear suggestion on what is causing the error. Not discounting the possibility of this being a regression, however we would need to see a reproducing app to better understand the nature of the error.

  3. Mike-E-angelo commented on Sep 7, 2021

    @Mike-E-angelo

    however we would need to see a reproducing app to better understand the nature of the error.

    Hi @eiriktsarpalis thank you for your investigation of this issue. As stated in the ticket a csproj was provided and attached. You may also find the same project here for your review:

    https://github.com/Mike-E-angelo/Stash/tree/master/Syncfusion.Error/WebApplication1

    Please do let me know if you require any further information and I will do my best to assist. 👍

  4. eiriktsarpalis commented on Sep 7, 2021

    @eiriktsarpalis
    Member

    Thanks, we'll investigate.

  5. eiriktsarpalis commented on Sep 8, 2021

    @eiriktsarpalis
    Member

    I can reproduce the issue locally. As the error message suggests, this is an issue with the syncfusion components. The Syncfusion.Blazor.Grids.GridColumn.EditTemplate property has a System.Text.Json.Serialization.JsonConverterAttribute that specifies a TemplateConverter converter that derives from Newtonsoft.Json.JsonConverter instead of System.Text.Json.JsonConverter. This should explain the error message.

    I would recommend filing an issue with the maintainers of syncfusion.

  6. added and removed
    untriaged
    on Sep 8, 2021
  7. Mike-E-angelo commented on Sep 8, 2021

    @Mike-E-angelo

    That was my impression as well @eiriktsarpalis. As stated in a comment on the developercommunity ticket this has been reported to Syncfusion as well.

    However, the confusing part to me is that this works if you switch to preview-7. Why does it work in preview-7 and not RC1?

  8. eiriktsarpalis commented on Sep 8, 2021

    @eiriktsarpalis
    Member

    However, the confusing part to me is that this works if you switch to preview-7. Why does it work in preview-7 and not RC1?

    Are you sure no other moving parts have come into play? The particular syncfusion converter is clearly broken and would fail with this error in all releases of System.Text.Json.

  9. Mike-E-angelo commented on Sep 8, 2021

    @Mike-E-angelo

    Try switching to preview7 on your side and watch the magic, @eiriktsarpalis. :)

    I was able to get it to work/break simply by switching between the two SDKs. In fact, Syncfusion couldn't reproduce it on their side when I initially reported it to them. It wasn't until I switched back to preview7 that it worked as they saw it as well. If you follow the thread there I requested they try RC1 and that is when they filed the bug on their end.

    This is definitely a versioning regression, and I agree with your conclusion on what is wrong, but I am still unclear on why this worked in preview7 (and net5.0 as well).

  10. 16 remaining items

  11. mayur-ekbote commented on Sep 15, 2021

    @mayur-ekbote

    @eiriktsarpalis Did you get a chance to test it between .net 6 previews vs RC1? Specifically, was this JsonIgnore behavior introduced in RC1?

  12. eiriktsarpalis commented on Sep 16, 2021

    @eiriktsarpalis
    Member

    Culprit seems to be this change: 91021fe#diff-814722ef5303e65815d350762206450b283510f6246b658047c4dffd31c97920L59-L64

    @layomia could you take a look? Not sure why order was swapped. Should we consider reverting for .NET 6?

  13. layomia commented on Sep 16, 2021

    @layomia
    Contributor

    The order was swapped for infrastructural reasons to support the src-gen parameterized ctor feature. I'll investigate a fix for the regression here. I do hope that the maintainers of Syncfusion can address the converter misconfiguration issue in the event that this doesn't meet the bar for a 6.0 fix.

  14. Mike-E-angelo commented on Sep 16, 2021

    @Mike-E-angelo

    FWIW my concern is not only for Syncfusion but others who may be in employing the same method in their serialization(s) as well. It will break for them too once they onboard to RC1+. If it is documented under breaking changes somewhere then I am OK with that as well. But that's just my vote/take/preference.

  15. mayur-ekbote commented on Sep 17, 2021

    @mayur-ekbote

    Devs might be using [JsonIgnore] like the left-hand operand of && that always evaluates to a fixed value. Possibly to postpone making more structural changes when .net moved from newtonsoft to system.text in 3.1 (clearly the case with Syncfusion).

    This will introduce runtime-breaking changes that might go unnoticed for a while. Unlike some other breaking changes that impact a startup-config or EF core (entirely in the domain of the app developer to fix), this change will affect libraries that would be completely out of the control of the developer. Till the 3rd parties (and their transitive dependents) fix this, the developer won't be able to migrate to .net 6. There is a lot riding on .net 6: MAUI, hot reload, blazor mobile bindings, and so on.

    Since it is breaking the [JsonIgnore] contracts of prior versions, it would be futile to keep it on the roadmap for .net 7. If it is not fixed in .net 6, the workaround would have been implemented by the time .net 7 arrives.

    I hope a wider consultation is held before any call is made on this issue.

  16. eiriktsarpalis commented on Sep 20, 2021

    @eiriktsarpalis
    Member

    Triage: reverting the change in 91021fe#diff-814722ef5303e65815d350762206450b283510f6246b658047c4dffd31c97920L59-L64 at this stage carries risk and it does not meet the bar for servicing RC2. Reported issue is due to a bug in a third-party library which depended on undefined behavior in System.Text.Json: its maintainers are already working on a fix.

    I have created #59364 to track making JsonIgnoreAttribute semantics well-documented and consistent in a future release of System.Text.Json.

  17. Mike-E-angelo commented on Sep 20, 2021

    @Mike-E-angelo

    Works for me, @eiriktsarpalis. Thank you for all your efforts out there, both to you and your team. 🙏

  18. rajendranr-5483 commented on Sep 27, 2021

    @rajendranr-5483

    Hi @eiriktsarpalis / @Mike-E-angelo,

    I work for Syncfusion. We have faced serialization issue with DataGrid, TreeGrid and Toolbar components alone when migrating from .NET 6 Preview 7 to .NET 6 RC1. Since, we have used TemplateConverter in these components. We have resolved the compatibility related issues and included with 2021 Volume 3 release, which is ready to roll-out within this week.

    Currently, we are compiling our Blazor source using netstandard 2.1 and net 5.0. We planned to compile our source using .NET 6 Target from upcoming 2021 Volume 4 releases.

  19. timkempster commented on Sep 28, 2021

    @timkempster

    Thanks for the update rajendranr-5483. Please can you post here when you have released so we can give it a spin. I'm really suffering with this one. I tried to go back to a downgrade but it casued all sorts of other issues so I'm stuck waiting for Synchfusion before I can continue to work in any meaningful way.

  20. rajendranr-5483 commented on Sep 28, 2021

    @rajendranr-5483

    @timkempster ,

    Sure, we have planned to roll-out the 2021 Volume 3 release on or before 1st October.

    I will update here once release will be rolled-out.

  21. Mike-E-angelo commented on Sep 30, 2021

    @Mike-E-angelo
  22. ghost locked as resolved and limited conversation to collaborators on Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions