Add UserData: Object Reference not set to the instance of an object


Hi, I got this error when add UserData to the attributes of the object.

System.NullReferenceException: Object reference not set to an instance of an object.
   at Rhino.DocObjects.Custom.UserData.NonConstPointer(Boolean createIfMissing)
   at Rhino.DocObjects.Custom.UserDataList.Add(UserData userdata)

I am following this sample

MyUserData class is inherited from DocObjects.Custom.UserData

I am adding user data directly to the attributes of RhinoObject:

Where can be the problem?

I see it leads to UserData.NonConstPointer but no idea what is wrong there.



Just digging a bit more i have found the following topic from @menno

Bug has been registered under:
And I see the state is open.

@stevebaer, can you please comment? How to overcome this?
I am adding UserData from GH custom component.

(Steve Baer) #3

This won’t be implemented any time soon. It will take quite a bit of core changes to allow for custom UserData to be defined by something other than a plug-in. I would recommend using the UserDictionary if at all possible.


Thank you, @stevebaer
It is a pity that it is even not planned so far as it limits possibility to write custom classes.

Is it any example of using UserDictionary for some Custom class which is a bit more complicated than key-string value?


(Steve Baer) #5

UserDictionary supports a lot more than just string values

UserString on the other hand is just a dictionary of key/value pairs where all of the values are strings.


Thanks, @stevebaer

UserDictionary works quite good. The easiest solution I found is to serialize/deserialize custom class into/from Byte array.