SPEventReceiverStatus.CancelNoError is showing error even though it is not supposed to

Frank Martin 476 Reputation points
2024-10-15T17:28:37.7566667+00:00

I am developing GroupUserAdding event receiver in which I am using SPEventReceiverStatus.CancelNoError but it is still throwing error Sorry, something went wrong when someone tries to add user in group. It is for SharePoint 2016.

Why is this throwing error when it should not?

Here is my code:

public override void GroupUserAdding(SPSecurityEventProperties properties)
{
    base.GroupUserAdding(properties);
    base.EventFiringEnabled = false;
    properties.Status = SPEventReceiverStatus.CancelNoError;
    base.EventFiringEnabled = true;
}
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,622 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Xyza Xue_MSFT 25,806 Reputation points Microsoft Vendor
    2024-10-16T06:19:58.0933333+00:00

    Hi @Frank Martin ,

    The SPEventReceiverStatus.CancelNoError status is used to cancel the event without showing an error message. However, if there is an underlying issue, such as permissions or configuration problems, it might still result in an error. Check the SharePoint ULS logs for more detailed error messages that could provide additional insights.

    Permissions: Ensure that the account running the event receiver has the necessary permissions to add users to the group. Lack of permissions can cause unexpected errors.

    Code Adjustment: Try adjusting your code slightly to ensure the event firing is handled correctly. Here is a revised version of your code:

    public override void GroupUserAdding(SPSecurityEventProperties properties)
    {
        base.EventFiringEnabled = false;
        properties.Status = SPEventReceiverStatus.CancelNoError;
        base.GroupUserAdding(properties);
        base.EventFiringEnabled = true;
    }
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.