FixedString64Bytes reporting the wrong length on the client

I have a problem with FixedString64Bytes in INetworkSerializeable in a network variable. ON the client it is throwing an error saying that the length is 605 bytes when the string is empty.

The code is as follows:

public struct SerializableMaterialHash : INetworkSerializable, IEquatable<SerializableMaterialHash>
{
    public FixedString64Bytes Name;
    public Color Color;

    public SerializableProperty[] properties;


    public bool Equals(SerializableMaterialHash other)
    {
        return Name == other.Name && Color == other.Color;
    }

    // INetworkSerializable
    public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
    {
        if (serializer.IsReader)
        {
            // De-Serialize the data being synchronized
            var reader = serializer.GetFastBufferReader();
            reader.ReadValueSafe(out Name);
            if (Name == "") return;
            reader.ReadValueSafe(out Color);
            reader.ReadValueSafe(out int numprops);
            properties = new SerializableProperty[numprops];
            for (int i = 0; i < numprops; i++)
            {
                reader.ReadValueSafe(out FixedString64Bytes Key);
                reader.ReadValueSafe(out float Value);
                properties[i] = (new() { Key = Key, Value = Value });
            }
        }
        else {
            var writer = serializer.GetFastBufferWriter();
            writer.WriteValueSafe(Name);
            if (Name == "") return;
            writer.WriteValueSafe(Color);
            if (properties == null)
            {
                writer.WriteValueSafe(0);
                return;
            }
            writer.WriteValueSafe(properties.Length);
            foreach( SerializableProperty prop in properties)
            {
                writer.WriteValueSafe(prop.Key);
                writer.WriteValueSafe(prop.Value);
            }
        }
    }
}

I tried your code and didn’t get any errors. Are you using the latest version of NGO?

I am using the latest version of NGO but I also tried regarding NGO back to 1.9.1 to test and it seems the same.

I am not sure “how” this site could happen on the client - surely the purpose of Fixed string is to avoid that.

Assuming Serializable.Key is of type FixedString64Bytes and SerializableProperty.Value is of type float, the code doesn’t seem problematic. Fixed string types are encoded as a length followed by that number of bytes for the string content. Reading a size larger than is supported given a fixed string instance’s capacity would be an error. WriteUnmanagedSafe/ReadUnmanagedSafe could be used if you want to remove that as a factor, though it’s probably not the cause of the issue. A likely explanation is some previously written data does not have a correct serialization implementation and offsets the reading or writing position inappropriately.

Interesting - that would mean that the error is actually in another network variable I guess. I had not thought of it like that.

I will have to go away and check that out.

Thanks

For information - the problem was caused by a badly serialized Enum in a totally different Network Variable.