I'm trying to debug a server solution which stopped working when it was migrated into SP 2019 (not sure if it was migrated from 2013 or 2016). The solution is using SPSecurity.RunWithElevatedPrivileges in an event receiver.

SPSecurity.RunWithElevatedPrivileges(delegate ()
    using (SPSite site = new SPSite(properties.SiteId))
        using (SPWeb web = site.OpenWeb(properties.Web.ID))

The code modifies the permissions of documents uploaded and saved into a document library if 'Protection' is selected as the value of a particular field.

The code is clearly running under the app pool account in the debugger, but it is only working when the user is a site collection admin. In other words it is actually running with the permissions of the user who uploaded/saved the document.

Can anyone hazard a guess as to what might be going on or suggest how to go about debugging it?

  • Where code is broken? After OpenWeb? Commented Sep 15, 2023 at 5:45
  • The code breaks at the statement: item.BreakRoleInheritance(true); I have realised that it does not happen when the item is an email message file. It does happen when the item is a pdf or word file
    – Rogerb
    Commented Sep 21, 2023 at 8:19


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.