Hi all,
I have constructed a class that contains among others a dictionary like this:
[Serializable()]
public class MyObject
{
public Dictionary<string, IGH_Goo> myDictionary = new Dictionary<string, IGH_Goo>();
....
}
[Serializable()]
public class GH_MyObject : Grasshopper.Kernel.Types.GH_GeometricGoo<MyObject>, IGH_PreviewData, IGH_BakeAwareData, GH_ISerializable
{
....
}
This way I can relate a key to a Grasshopper entity (GH_Integer, GH_Curve, GH_Point…), let’s say anything wrapped in a IGH_Goo and dynamically modify this dictionary on the go…
Based on this class I managed to pass it around between components as a GH_MyObject and to use it as an input:
pManager.AddParameter(new Param_MyObject() );
Last thing now is to make sure I can Internalize this data at an input node or inside a param-component… It turns out GH_Integer, GH_Curves, etc. are not serializable?
How to make the class I have serializable? What do I forget or what do I not see?
When internalizing these GH_Entity’s in grasshopper, how is the serialization done?
If someone might help me out, thanks!
Have a nice day.
The exception I get can be found underneath:
System.Runtime.Serialization.SerializationException: Type ‘Grasshopper.Kernel.Types.GH_Integer’ in Assembly 'Grasshopper, Version=7.2.21021.7001, Culture=neutral, PublicKeyToken=dda4f5ec2cd80803’ is not marked as serializable.
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func
2 valueFactory)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArrayMember(WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, Object data)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at GH_MyObject.Write(GH_IWriter writer)