GetObjectData not being called on base classes

SilverShaded

Well-known member
Joined
Mar 7, 2020
Messages
93
Programming Experience
10+
I'm having a weird problem, I have a bunch of classes that are saved using binary serialisation, the top level class is being created in another project and serialiased from there, this is failing to call the GetObjectData methods on some base classes (but not all). If i create a new project and serialise it from there it works perfeclty, ie the base classes are serialised/de-serialiased correctly. I have not posted code yet because i have no idea what i need to post. The code I post will probably work fine, it just doesnt work when called from the seperate "main" program). I cant see any different in the way the code is called or the data it is trying to save ??
 
Firstly, welcome to the forums.

So what do you expect us to do? Magic up a miracle that immaculately and miraculously conjures up the exact same functionality and inherent problem as you are experiencing?

Post your code, and the relevant serialised objects (if not to personal) so we can begin to analyse a possible cause.

Also post your project config file!
 
Its got more complicated than that. I have two versions of the code which are actually identical (i have checked with WinMerge). The only difference is some characters in the SLN files and CSproj files. One version is flaky and the other one is working ok. By flaky I mean the first time i run through some code which serialises then deserialises it fails to retireve a value (defaults to 0 for a double), second time it runs its ok. The other copy works perfeclty first time through. So at this point posting code isnt going to help. It seems to be something odd or corrupted in the sln or csproj file that is causing an issue. Maybe ill try create a new sln and csproj files and see if that works, at least then i know probably where the problem is if not the exact cause (maybe VS2019 is a bit buggy still).

Edit: Ok it works as a standalone project, but when added to a bigger solution and set as the startup project, it fails (doubles are read back as zero). Please let me know which files would be relevant and ill post them, thanks for your help.
 
Last edited:
Well, since the standalone project works fine, it will be up to you to trim down the bigger version of the project so that it acts flakey. For now, post the standalone project so that we can start wrapping our head around what you are doing, and how things work when they are supposed to work normally.

It looks like you've already done some debugging and found part of the issue where the serialization callback is not being called. Have you tried adding more logging to see if things are being called in the same order? Have you looked out the serialized data? Is the flakiness on serialization or on deserialization?

Personally, without seeing your code, my suspicions would go towards making assumptions about hash code values for strings; or inconsistent builds/runs that leave turds behind.

The Framework only guarantees consistency within a single process' lifetime. You can't rely on the hashcode generated right now for a given string to be the same the next time you run a program.

If your builds are reliant on intermediate artifacts, or if running your code is reliant on some files on disk, there maybe a logic error where an old artifact/file is being used on the next run, and there by messing things up.
 
I was mistaken, too tired and trying everything i can think of to get this to work, confised myself. The standalone version is not working either. The Components object deserialises correclty when used from a Port object(which is located on another object in the ModelStack) in Flowsheet. It just fails when deserialised direclty into the Flowsheet object. I could probably hack somethingthat works by storing another object in the model stack just to store a 'Master' Data list. But thats an ugly solution and it baffles me why this doesnt work. Im more than happy to send the whole solution if it can help.
 
Well another week and a monday morining with a clear head i found the issue. There was another componenet type inheriting from BaseComp that was being added to the stack being serialised and wasnt being deserialized! Problem solved. Thanks for your help, my code needs a good and long overdue cleanup...
 
Although it would make your serialized data bigger, it maybe worth sticking on a "object type" field in the serialized data, as well as a "size of object".
 
Yep, im expecting stored file size to be up to 100MB eventually so a bit more is no issue. Some of this i wrote twenty years ago, needs a revisit :)
 
Back
Top Bottom