Can't add custom UserData to Layer? (rhinocommon)

I am able to add an item to the UserDataList member (UserData) of a layer, but only if it is a pre-defined UserData class like UserDictionary. If I try to add my own data derived from Rhino.DocObjects.Custom.UserData, I get an exception (“Object reference not set to an instance of an object.”). My UserData-derived class looks like this:

 [Guid("359B9A80-5937-4C55-A35E-367E968B933D")]
    public class OrcaReferenceLayer : UserData
    {
        public OrcaReferenceLayer() : base() { }
        public override string Description
        {
            get
            {
                return "orca reference layer";
            }
        }
        public override string ToString()
        {
            return "Orca Reference Layer";
        }
    }

I have also tried adding a PhysicalData item from the example code to no avail. Is there something obvious I am doing wrong?

Hi Bill,

I’ve added some layer samples to my user data example.

https://github.com/dalefugier/SampleCsUserData

Let me know if this is helpful.

– Dale

Thanks, Dale.

Oddly, it appears to have something to do with our project settings…I even went so far as to copy your commands into my plugin, and they crash in my plugin but work fine in yours. Unless you can think of anything else obvious.

Thanks, Dale, I figured it out. I was stupidly putting the UserData class in an assembly other than the plugin assembly and didn’t pick up on the fact that it needs to be picked up in the reflection mechanism and registered. Simple PEBCAK error.