Search Issue Tracker
In Progress
Under Consideration for 2020.3.X, 2023.1.X
Fix In Review for 2021.3.X, 2022.2.X, 2023.2.0a1
Votes
1
Found in
2021.3.17f1
2022.2.3f1
2023.1.0a26
2023.2.0a1
Issue ID
UUM-23156
Regression
Yes
[IL2CPP] InvalidCastException is thrown when serializing jagged arrays using BinaryFormatter
How to reproduce:
1. Open the user’s attached “ErrorDemo” project
2. Build and Run the “SampleScene” Scene on Android
3. Observe the logs
Expected result: Jagged arrays are successfully serialized and the corresponding errors aren’t thrown
Actual result: InvalidCastException error is thrown
Reproducible with: 2021.3.15f1, 2021.3.17f1, 2022.2.3f1, 2023.1.0a26
Not reproducible with: 2020.3.44f1, 2021.3.14f1
Reproduced on: macOS 13.0 (Intel)
Thrown error:
InvalidCastException: Unable to cast object of type 'Int32[]' to type 'Object[]'.
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo memberObjectInfo) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo typeNameInfo) [0x00000] in <00000000000000000000000000000000>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize (System.Object graph, System.Runtime.Remoting.Messaging.Header[] inHeaders, System.Runtime.Serialization.Formatters.Binary.__BinaryWriter serWriter, System.Boolean fCheck
Reproducible with devices:
VLNQA00494 - iPhone 14 Pro Max, 16.0.3 iOS
VLNQA00472 - Samsung Galaxy A52 (SM-A525F), CPU: Snapdragon 720G (SM7125), GPU: Adreno 618, OS: 12
VLNQA00414 - Galaxy Note10+ 5G (SM-N976V), CPU: Snapdragon 855 SM8150, GPU: Adreno 640, OS: 9
VLNQA00409 - Galaxy Z Fold3 5G (SM-F926B), CPU: Snapdragon 888, GPU: Adreno 660, OS: 11
VLNQA00392 - iPad (9th generation), 15.0 iOS
VLNQA00358 - iPhone 12, 14.1 iOS
VLNQA00335 - Galaxy S20+ 5G (SM-G986B), CPU: Exynos 990, GPU: Mali-G77, OS: 10.0.0
-
dualcarbongames
Jan 21, 2023 09:58
not sure but it might help,
we have our project in unity 2020.38.f1, tried to update it to newer versions and stuck with the same issue, then to make things simpler created a new project to quickly check on different unity versions, findings below..
BinaryFormatter.serialize() produces the InvalidCastException only for Integers jagged arrays, rest of the basic type variables jagged arrays are fine(float, string, bool), this happens only on the build and not in the editor.
tested only on Mac OSX for editor and on iOS build,
in editor, its all good, no errors at all in any unity versions, BinaryFormatter.serialize() will work perfectly fine as it should do for integers jagged arrays, but will through error in the build.if you are loading saved data previously saved through BinaryFormatter, no issues at all, it will load the integers jagged array without any problem.
produceable on unity 2020.3.44f, 2021.3.16f1, 2022.* .
not produceable on 2020.38f1, 2020.43.f1
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Quest 2] Surface shader and multi-view sampling custom textures broken in Quest 2
- Lighting Data asset is not created when baking multiple Scenes at the same time
- Performance issues when instantiating a recognizer under UnityEngine.Windows.Speech
- Build fails with "Exception: Unity.IL2CPP.Building.BuilderFailedException: Build failed with 0 successful nodes and 0 failed ones" when building the project for iOS
- [Android] .aab Build fails when using Asset Bundles
Resolution Note (fix version 2023.2.0a1):
A patch was made to the Il2Cpp tool to handle a recent regression that caused casting between array types to fail.