Just a guess, but maybe the feature you're trying to add the attachment to isn't "loaded". We actively prevent edits to features that aren't in the loaded state.
Can you try calling the "load()" method on the feature first, and after it finishes loading see if the addAttachment() call works.
We expect calling asynchronous methods like addAttachment() would internally first load the feature, but maybe it was missed in this particular case