Search Issue Tracker
Fixed
Fixed in 2020.3.47f1, 2021.3.20f1, 2022.2.9f1, 2023.1.0b6, 2023.2.0a1
Votes
4
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
Comments (5)
-
stdev33
Nov 10, 2023 09:43
Maybe it is would be better not using of BinaryFormatter at all due to "Deserialization risks in use of BinaryFormatter and related types" described in particular post at learn.microsoft.com
-
LeonHiggin
Apr 27, 2023 14:20
DUAL CARBON GAMES You are an absolute life safer!
-
dakota_curiousco
Feb 08, 2023 21:10
Hello we run into this issue with running Android on the Oculus with Unity 2021.3.16 with byte arrays.
Reproducible in Android Unity 2021.3.16
-
JJRivers
Feb 08, 2023 11:37
This also happens with byte arrays, issue is present in 2021.3.18f1 but is Not present in 2021.3.14f1
-
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
- Buttons in the Overlay Menu in the Scene View are all gray even if they're activated when Game View is maximized and minimized
- NullReferenceException is thrown when baking Adaptive Probe Volume for a Terrain with Non-GI Contributing Tree Prototypes and multiple APV objects with different LayerMasks are present on the scene
- Hands are not recognized when using Hololens 2
- "OnTriggerExit2D" is called before "OnTriggerEnter2D" when object is destroyed immediately
- Editor crashes on PrepareSpriteTilingData when exiting Play mode
Resolution Note (fix version 2023.2.0a1):
Fixed in 2023.2.0a1
Resolution Note (fix version 2023.1.0b6):
Fixed in 2023.1.0b6
Resolution Note (fix version 2022.2.9f1):
Fixed in 2022.2.8f1
Resolution Note (fix version 2021.3.20f1):
Fixed in 2021.3.20f1
Resolution Note (fix version 2020.3.47f1):
Fixed in 2020.3.47f1