COMException 0x81020089 in ItemAdding

(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.

3 thoughts on “COMException 0x81020089 in ItemAdding”

  1. Hello Edin,

    When you set SPItemEventProperties.Cancel = true; the SPItemEventProperties.Status property is automatically changed to CancelWithError (WSS realm), does it make any diference to change Status before setting the Cancel = true?

    BTW, this error also occours in itemUpdating.

    Cheers

  2. Doesn’t work at all for me (SPPS 2010)…
    My code:

    if (errorCondition)
    {
    properties.Status = SPEventReceiverStatus.CancelWithError ;
    properties.ErrorMessage = “My error text!”;
    properties.Cancel = true;
    }

    Still getting page with this COMException and my “My error text!” added there. But I the error page ONLY with my text.

  3. No matter what order I place the following lines of code in the ItemUpdating event receiver method:

    properties.Status = SPEventReceiverStatus.CancelWithError;
    properties.Cancel = true;
    properties.ErrorMessage = “Validation error”;

    I get the COMException and the rather ugly IIS server error page. For a moment, I was excited to come across your post, but the issue persists.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.