wyrd Posted August 1, 2003 Posted August 1, 2003 I've been trying to track down a deserialization error I've been getting for a while now, and I think I found the cause. The error I was getting is when trying to deserialize from a file.. and yes I'm using StreamingContextStates.File. Here's the error; "The object with ID 4097 was referenced in a fixup but has not been registered." The class in which I serialize is nothing more then a two dim array, structs, a bool value, and some strings. The two dim array is made up of structs. Being confused as I was, I marked the two dim array so it wouldn't serialize. Oddly enough, the deserialization worked after that (after reserializing the altered class of course). I tried serializing both a jagged array and a regular array; stuff[][] and stuff[,]. Both give the deserialization error. Marking this two dim array to not serialize is not an option, neither is using an ArrayList in replace of it. Is there any way to fix this? I'm still confused as to why a two dim or jagged array will not serialize and deserialize correctly. Thanks in advance. Quote Gamer extraordinaire. Programmer wannabe.
*Gurus* Derek Stone Posted August 1, 2003 *Gurus* Posted August 1, 2003 The two dim array is made up of structs. Are those structures marked as serializable? Quote Posting Guidelines
wyrd Posted August 1, 2003 Author Posted August 1, 2003 Yes. Are those structures marked as serializable? Quote Gamer extraordinaire. Programmer wannabe.
wyrd Posted August 1, 2003 Author Posted August 1, 2003 More info.. It seems to work when de/serializing in XML format, however the problem is with binary. *boggled* I upload the XML serialized file so you could see what's being serialized, and also below is the relevant code to the problem; Serialized file: http://www.danpeverill.com/test.xml // NOTE: XML and binary serialization code is identical, // just replace one formatter for the other. [NonSerialized] private Bitmap _areaImages; [NonSerialized] private TextureBrush[][] _areaTextures; private MapArea[][] _map; private Size _areaSize; private Size _mapSize; private Rectangle _camera; private string _name = ""; private string _desc = ""; [NonSerialized] private bool _disposed = false; public static Map Load(string path) { try { FileStream file = new FileStream(path, FileMode.Open); StreamingContext context = new StreamingContext(StreamingContextStates.File); SoapFormatter formatter = new SoapFormatter(null, context); Map map = (Map) formatter.Deserialize(file); file.Close(); return map; } catch (Exception e) { Console.WriteLine(e.Message); return null; } } public static bool Save(Map map, string path) { try { FileStream file = new FileStream(path, FileMode.Create); StreamingContext context = new StreamingContext(StreamingContextStates.File); SoapFormatter formatter = new SoapFormatter(null, context); formatter.Serialize(file, map); file.Close(); return true; } catch (Exception) { return false; } } Any ideas on how to fix this for binary? Quote Gamer extraordinaire. Programmer wannabe.
*Gurus* Derek Stone Posted August 2, 2003 *Gurus* Posted August 2, 2003 Your code looks fine. It appears you're the lucky recipient of BUG 320079. Congratulations! Seriously though... the binary formatter has a known problem with deserializing structures, arrays of structures and nested structures. I strongly suggest you convert to classes, which is the only true fix I've been made aware of. Quote Posting Guidelines
wyrd Posted August 2, 2003 Author Posted August 2, 2003 Ugh. :( Oh well, thanks for the info. Quote Gamer extraordinaire. Programmer wannabe.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.