Unable to catch a bug when serializing

Hi all, @DavidRutten,

For some reason, the Write() method in my gh types (inheriting GH_Goo) are never called. I don’t know what’s going on.

I have custom parameters and types inheriting from GH_PersistentParam< T> and GH_Goo< T> that are abstract classes (Param_Base and Goo_Base) and also other classes that inherit these. The abstract classes override the Write() and Read() methods just to check if they are being called, like this:

In the param:

    public override bool Write(GH_IWriter writer)
    { 
        RhinoApp.WriteLine("Write Param_Base");  // this returns as expected
        foreach (var d in PersistentData.FlattenData())
            Rhino.RhinoApp.WriteLine(d.ToString()); // this returns as expected, all data is there
        return base.Write(writer);
    }

In the goo:

    public override bool Write(GH_IWriter writer)
    {
        RhinoApp.WriteLine("Write Goo_Base");  // this call never happens!
        return base.Write(writer);
    }

The non-abstract classes doesn’t implement this methods. For some reason, Goo_Base.Write() is never called.

I check a .ghx file and its chunk is missing the data of the values:

                    <chunk name="PersistentData">
                      <items count="1">
                        <item name="Count" type_name="gh_int32" type_code="3">1</item>
                      </items>
                      <chunks count="1">
                        <chunk name="Branch" index="0">
                          <items count="2">
                            <item name="Count" type_name="gh_int32" type_code="3">1</item>
                            <item name="Path" type_name="gh_string" type_code="10">{0}</item>
                          </items>
                        </chunk>
                      </chunks>
                    </chunk>

This is the third time I’ve tried to fix this, I need help, I don’t know what could be going wrong. Another strange thing is that the Extract Parameter doesn’t work, it doesn’t do anything.

Hierarchy of inheritance:

 Param_Base< T> : GH_PersistentParam< T>
 Param_Foo : Param_Base< Goo_Foo>
 Goo_Base< T> : GH_Goo< T>
 Goo_Foo : Goo_Base< Foo>

I’ve done this a thousand times and it worked, and it’s too much code to turn everything upside down to look for the error, so I need to understand better why the parameter Write method doesn’t call the goo Write method, PersistentData has values.

Please help.

Without a minimal code example which fails it’s quite difficult to try and find the error.

If there’s an exception in the Write method it’ll silently remove that portion of the persistent data, but it may well be something else is wrong…

Just checking, does your goo derived type come with a public, empty constructor?

Anyway, here’s a minimal example of a parameter with functional write/read of two custom types.

CustomTypeWriteReadTest.cs (3.0 KB)

What’s the purpose of overriding the Write method of the Parameter? I don’t have that in any of my parameters, all my writing happens inside the Goo Wrapper class (which often just calls the serialization and deserialization methods of their custom type).

I can’t really reproduce this…

image

That was happening, I didn’t expect the exceptions to not jump up while debugging. Thank you very much.

Just for debugging in this case, but this has sense to store custom statetags or other parameter fields.