AmbiguousMatchException at ArchivableDictionary.AddContentsFrom()

In a plugin written in C# I need to store custom UserData (“MyMetadata”) in several objects, where this objects can share the same instance of MyMetadata.

For some reason I can’t store my data in the UserData property of the attributes, because every time I do it in the second object, the reference in the first object becomes null. As it says in the description of the UserDataList.Add() method:

If the userdata is already in a different UserDataList, it will be removed from that list and added to this list.

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_Custom_UserDataList_Add.htm
Is there any way to avoid this inconvenience?

My intent is to use the UserDictionary property instead, as my data is not just strings. However I get this exception :

System.Reflection.AmbiguousMatchException: Ambiguous match found.
       at System.DefaultBinder.SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
       at System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
       at System.Type.GetMethod(String name, Type[] types)
       at Rhino.Collections.ArchivableDictionary.AddContentsFrom(ArchivableDictionary source)

and the same happens with UserDictionary.ReplaceContentsWith().

My dictionary input comes from a method of MyMetadata which has not given me problems before to save the same data in the document, in the UserData property in the objects. But because it can’t be shared in several objects, I need an alternative. Please help, I have no idea how to deal with this exception, since it doesn’t look like my code or there’s no documentation to use the method properly…

If there were me, I’d store a list of MyMetaData objects as document user data. Then, for each object that needs a reference to it, I’d set the id or index of the MyMetaData item on the object.

Make sense?

– Dale

Makes sense. Thank you Dale.