COMException 0x81020089 in ItemAdding
May 28, 2009
(Thanks to my work colleague Cesar for pointing out this case to me)
SYMPTOMS
You have a custom list event receiver in SharePoint. You trap the ItemAdding event and you perform a validation logic to determine if the item should be added to the list. You determine that it’s not the case and you want to inform the user.
So, you set the ErrorMessage property of SPItemEventProperties to the desired text and you set Cancel property to True.
SharePoint throws a COMException 0x81020089 error with or without your error message.
CAUSE
By setting Cancel to True, you are instructing SharePoint to raise an exception. If you don’t treat the exception, it is shown as such and displayed to the end user.
SOLUTION
Set the SPItemEventProperties.Status property to CancelNoError (no error will be shown) or CancelWithError (error will be shown) before setting Cancel to True.