I asked the same question on stack overflow, without answers, so I will link it here. Basically, I'm getting null reference exception on this code:
_doc.CurrentSelection.CopyFrom(selection);
but neither _doc, CurrentSelection or selection are null or empty.