I keep forgetting Base objects can't use "Item" as a dynamic member

When The Rant Over GIF - Rant Rant Over End Of Rant - Discover & Share GIFs

LOL, I found this on our code this week, so your guess is as good as mine at this point :sweat:

Item is a member of IDictionary but as Item[]

So if you add Item[] as a member that is totally fine. :exploding_head:

The exception doesn’t give many clues: Parameter Count Mismatch.

BaseObject["Item"] => error
BaseObject["Item[]"] => fine

I’ve added a sanitization routine for property names now - perhaps that should be in Core.Core.Models.DynamicBase itself under IsPropertyNameValid


1 Like

I’ll let @dimitrie weigh in on this one, but I’m not against it :wink:

1 Like

It’s still kicking the can down the road. Item is problematic because of DynamicObject, IDynamicMetaObjectProvider inheritance of Base. I’d happily be in favour of swapping that for a simpler Base : Dictionary<string, object> - which is perfectly ok functionality wise, though a drop-in replacement might be difficult…

1 Like

Okay, I’ve dug into this a bit more. Item was actually hidden in plain sight, as this property:

I have a local fix that allows for Items to be set as dynamic props, as well as typed properties inside custom classes (also doing some fly-by caching and DRY-ing things up). Now I’ve also got the itch to cleanup the mess that accumulated in there re getting members from objects - I’ll leave that for another holiday though.

PR here: fix(core): allows for `Item` to be set as a dynamic or typed prop in `Base`-derived objects by didimitrie · Pull Request #1422 · specklesystems/speckle-sharp · GitHub


Great. It was only a rant that I had previously stumbled on, worked around, and then forgot about when encountering it again.

Property names added by the dictionary method skip the validity check for serialization. I’ve raised a PR to the docs with a note about that.

1 Like