0

I'm working on a Unity project for the Hololens 2 which serializes user data and saves it as a json file to be accessed again later. What I have currently works fine when emulating in Unity but on the Hololens itself I get the following error when serializing:

ExecutionEngineException: Attempting to call method 'System.Runtime.Serialization.XmlObjectSerializerWriteContext::IncrementCollectionCountGeneric<UnityEngine.Vector3>' for which no ahead of time (AOT) code was generated.

After some testing I've found that my code works fine on the Hololens as long as I don't use any Vector3's which makes sense considering the error above. The issue I'm having is when Vector3 is being serialized in the json file it will simply cut off and leave incomplete json. I assume the issue is because of the missing method for serializing Vector3's when building for the Hololens (UWP).

How should I go about handling this from here?

CocoaMilka
  • 25
  • 7
  • Can you provide a snippet of your serialization code, and what the JSON should look like and what you're getting? Are you able to use a different data structure to get around the issue such as an array. – Nano Jul 06 '23 at 02:47
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jul 06 '23 at 02:47
  • How exactly are you serializing? can you share your relevant code? In general: Just use a custom `Vector3` implementation you'll be using just for the forth and back serialization between JSON and the `Vector3` used inside of the application – derHugo Jul 06 '23 at 07:08

1 Answers1

0

Unity strips code when building for platforms with AOT support (such as UWP which the Hololens uses) and this has a tendency to not generate AOT code that should be generated like the serialization code for my project. At the time I was using data contracts but switching over to json.net solved all of my problems.

CocoaMilka
  • 25
  • 7