Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Fix Queue/Stack deserializing with IL2CPP #53

Closed
applejag opened this issue May 10, 2020 · 2 comments
Closed

Fix Queue/Stack deserializing with IL2CPP #53

applejag opened this issue May 10, 2020 · 2 comments
Labels
bug:aot Troubles with Ahead Of Time compilation enhancement New feature or request wontfix This will not be worked on
Milestone

Comments

@applejag
Copy link
Owner

Description

As found in @felipegodias issue #51, the Queue<T> type cannot be deserialized in the IL2CPP runtime if not referencing the new Queue<T>(IEnumerable<T>) constructor as Json .NET apparently uses that parameterized constructor for said type.

https://github.com/JamesNK/Newtonsoft.Json/blob/12.0.3/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs#L194-L201

This assumably would also apply to the Stack<T> type. Would have to investigate if the non-generic Queue and Stack also would be fine. Difficult to test non-generic ones as anything that would generate the AOT code will make a test on non-generated AOT code not work properly.

Tricky!

Motivation

Possibility to deserialize Queue and Stack on IL2CPP runtime.

Suggested solution

Three possible solutions:

  1. Add ensuring of the constructor in AotHelper, but that does not help with types inheriting from Queue<T> as it's not possible to ensure other constructors than the default one generically.

  2. Add a custom converter for Queue<> and Stack<> types.

  3. Modify Json .NET to populate queues and stacks via their .Enqueue(T item) and .Push(T item) methods, respectively. Will have to investigate how this can be done with the least amount of changes to the Json .NET code as possible and distinguishable so I don't accidentally remove the fix later.

Nr 2 would be easiest to implement and give the best user experience, except for when users define their own converters. Perhaps hacky to force a converter in there. Which makes option nr 3 the dominating solution, and perhaps the most "best practice"-esque.

@applejag applejag added enhancement New feature or request bug:aot Troubles with Ahead Of Time compilation labels May 10, 2020
@applejag applejag added this to the 12.0.302 milestone Jan 10, 2021
@applejag applejag modified the milestones: 12.0.302, 12.0.303 Feb 19, 2021
@applejag
Copy link
Owner Author

This had to be forwarded to 12.0.303 as the changes from #54 were too important to delay further.

@applejag
Copy link
Owner Author

I'm closing this as I do not find it prioritized.

If anyone finds this issue while searching for an answer, the I would advice you to serialize a different type instead and only use a Stack or Queue in your deserialized workflows.

@applejag applejag added the wontfix This will not be worked on label Nov 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug:aot Troubles with Ahead Of Time compilation enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant