Serialization / Deserialization Issue

Hi All,

I’ve looked around the forums as I’m sure this has been asked before but coudln’t find the topic.
I’ve just begun to implement the GH_IO.Serialization reader and writer objects in a new library I’m working on where I want to provide robust data (de)serialization.

Below is a simple example where I’m prompting the user to select a network location using the Windows Folder Browser Dialog and then developing a component to incrementally rename analysis result files and save them to the folder.

When I save the file and reopen (expecting the directory path to still be present), the Select Folder component jumps to the canvas 0,0 position and I get an error stating that the component failed to deserialize correctly.

Can anyone see if I am not calling the reader and writer overrides correctly, or is it as simple as not allowing whitespace characters in the string writer method? Link to code snippet:

Thanks in advance :slight_smile:

If you override Write and/or Read, always call the base method classes:

public override bool Write(GH_IO.Serialization.GH_IWriter writer)
  writer.SetString("strPath", this.directoryPath);
  return base.Write(writer);

Perfect. I’ll make sure to always do that.
Thanks for the quick response David!

ps. if you’re writing data to gh files, did you know you can inspect the hierarchical structure using the viewer app? If you drag a gh file onto the canvas, then move it over the page-curl and pick the Examine option, it will open in a simple viewer.

Thanks for the heads up on that David, I hadn’t seen it before now.
It works great, I can browse to to the object and see the value stored as an item.
Are the definition objects in the viewer indexed by their position on the canvas or are they indexed sequentially when they are added to the document (always keeping their position in the viewer)?

Again, great work and thanks! :slight_smile: