Data deserialisation error (Object type cannot be converted to target type)
See original GitHub issueWhile testing the fix proposed in pull request https://github.com/VictorPhilipp/Cities-Skylines-Traffic-Manager-President-Edition/issues/189 I found that mod data was not persisting between game loads. After saving and quitting, then reloading the game, I found that I had to spend an hour remaking all of my lane connections, restrictions, speed limit changes, timed traffic lights, etc.
I’m not sure what the root cause is, but I also don’t think it’s the proposed pull either. When I was using workshop 1.10.8, this problem occurred (though I did not check for a stacktrace at that time).
Three days ago I was using TMPE 1.10.3, as a test to see if it fixes the PT bug which https://github.com/VictorPhilipp/Cities-Skylines-Traffic-Manager-President-Edition/issues/189 appears to fix. When I switched to that version, there was a bug with data resetting and me having to redo all of the above. This happened again when I switched to 1.10.7, also as a test, and again when I switched back to workshop 1.10.8.
I inspected TMPE.log (%programfiles(x86)%/Steam/steamapps/common/Cities_Skylines/TMPE.log
) and found a stacktrace (using the .dll’s provided in https://github.com/VictorPhilipp/Cities-Skylines-Traffic-Manager-President-Edition/issues/189).
[Error] @ 1485767776 Error deserializing data: System.ArgumentException: Object type System.Collections.Generic.List`1[TrafficManager.Configuration+ExtCitizenData] cannot be converted to target type: System.Collections.Generic.List`1[TrafficManager.Configuration+ExtCitizenData]
Parameter name: val
at System.Reflection.MonoField.SetValue (System.Object obj, System.Object val, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.FieldInfo.SetValue (System.Object obj, System.Object value) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.ObjectRecord.SetMemberValue (System.Runtime.Serialization.ObjectManager manager, System.Reflection.MemberInfo member, System.Object value) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.FixupRecord.FixupImpl (System.Runtime.Serialization.ObjectManager manager) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.BaseFixupRecord.DoFixup (System.Runtime.Serialization.ObjectManager manager, Boolean strict) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.ObjectRecord.DoFixups (Boolean asContainer, System.Runtime.Serialization.ObjectManager manager, Boolean strict) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.ObjectManager.RegisterObjectInternal (System.Object obj, System.Runtime.Serialization.ObjectRecord record) [0x00000] in <filename unknown>:0 traffic mana
at System.Runtime.Serialization.ObjectManager.RegisterObject (System.Object obj, Int64 objectID, System.Runtime.Serialization.SerializationInfo info, Int64 idOfContainingObj, System.Reflection.MemberInfo member, System.Int32[] arrayIndex) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.RegisterObject (Int64 objectId, System.Object objectInstance, System.Runtime.Serialization.SerializationInfo info, Int64 parentObjectId, System.Reflection.MemberInfo parentObjectMemeber, System.Int32[] indices) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) [0x00000] in <filename unknown>:0
at TrafficManager.State.SerializableDataExtension.DeserializeData (System.Byte[] data) [0x00000] in <filename unknown>:0
at CSUtil.Commons.Log.LogToFile(System.String log, LogLevel level)
at CSUtil.Commons.Log.Error(System.String s)
at TrafficManager.State.SerializableDataExtension.DeserializeData(System.Byte[] data)
at TrafficManager.State.SerializableDataExtension.OnLoadData()
at SerializableDataWrapper.OnLoadData()
at SimulationManager.LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
at SimulationManager.Managers_LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
at LoadingManager+<LoadSimulationData>c__IteratorB.MoveNext()
at AsyncTask.Execute()
at SimulationManager.SimulationStep()
at SimulationManager.SimulationThread()
[Info] @ 1485776767 at System.Reflection.MonoField.SetValue (System.Object obj, System.Object val, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.FieldInfo.SetValue (System.Object obj, System.Object value) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.ObjectRecord.SetMemberValue (System.Runtime.Serialization.ObjectManager manager, System.Reflection.MemberInfo member, System.Object value) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.FixupRecord.FixupImpl (System.Runtime.Serialization.ObjectManager manager) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.BaseFixupRecord.DoFixup (System.Runtime.Serialization.ObjectManager manager, Boolean strict) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.ObjectRecord.DoFixups (Boolean asContainer, System.Runtime.Serialization.ObjectManager manager, Boolean strict) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.ObjectManager.RegisterObjectInternal (System.Object obj, System.Runtime.Serialization.ObjectRecord record) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.ObjectManager.RegisterObject (System.Object obj, Int64 objectID, System.Runtime.Serialization.SerializationInfo info, Int64 idOfContainingObj, System.Reflection.MemberInfo member, System.Int32[] arrayIndex) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.RegisterObject (Int64 objectId, System.Object objectInstance, System.Runtime.Serialization.SerializationInfo info, Int64 parentObjectId, System.Reflection.MemberInfo parentObjectMemeber, System.Int32[] indices) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00000] in <filename unknown>:0
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) [0x00000] in <filename unknown>:0
at TrafficManager.State.SerializableDataExtension.DeserializeData (System.Byte[] data) [0x00000] in <filename unknown>:0
[Error] @ 1485780156 OnLoadData: Error while deserializing data: System.ApplicationException: An error occurred while loading
at TrafficManager.State.SerializableDataExtension.DeserializeData (System.Byte[] data) [0x00000] in <filename unknown>:0
at TrafficManager.State.SerializableDataExtension.OnLoadData () [0x00000] in <filename unknown>:0
at CSUtil.Commons.Log.LogToFile(System.String log, LogLevel level)
at CSUtil.Commons.Log.Error(System.String s)
at TrafficManager.State.SerializableDataExtension.OnLoadData()
at SerializableDataWrapper.OnLoadData()
at SimulationManager.LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
at SimulationManager.Managers_LateUpdateData(UpdateMode mode, Single minProgress, Single maxProgress)
at LoadingManager+<LoadSimulationData>c__IteratorB.MoveNext()
at AsyncTask.Execute()
at SimulationManager.SimulationStep()
at SimulationManager.SimulationThread()
[Info] @ 1485830500 An error occurred while loading.
To me, this is suggesting that my mod data may be corrupt, but I’m not sure. I will provide my save file if necessary to help find a solution to this.
Since the stacktrace mentions it, I’ll link in the SerializableDataExtension file.
As near as I can tell, the specific lines which are referenced are 40, 82 (and the immediately following catch statement), 121, 125, and 131. I believe it gets to at least line 131, as the stacktrace specifically mentions BinaryFormatter.Deserialize
.
My best guess for the cause of this is a corrupt save. That said, I’d still like to report it here and find out whether it is my save that is corrupt.
https://github.com/VictorPhilipp/Cities-Skylines-Traffic-Manager-President-Edition/issues/190
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
@aubergine10 In my opinion that is not a bug but a problem caused by the method we use to serialize/deserialize custom game data. We could use a different library for (de)serialization that handle differences in data structures more gracefully.
When reworking the load/save system we should not forget #149 and #179.
Additional information: This bug may have been caused by having two separate instances of the same mod operating. Even though one was disabled, only the original mod (the one first added) would properly read the save data. Would recommend investigating by using the two workshop versions of TMPE (this one and LF’s one).