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


#1

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:
robj.Attributes.UserData.Add(MyUserData)

Where can be the problem?

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

Thanks,
Dmitriy


#2

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

Bug has been registered under: https://mcneel.myjetbrains.com/youtrack/issue/RH-23446
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.


#4

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?

Thanks,
Dmitriy


(Steve Baer) #5

UserDictionary supports a lot more than just string values
http://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Collections_ArchivableDictionary.htm

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


#6

Thanks, @stevebaer

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