As part of a requirement I needed to create a plugin to set the ownership of a record prior to its creation as setting it after this event would not work for what the customer needed, this means that it would run on PreOperation and subsecuently set the property OwnerId to the resulting owner that will be retrieved after certain logic. However, once I deployed it to my DEV instance I started to see the next error:
Changing security attributes is not allowed in stage 20 plugins.
How to fix
This problem relies on the fact that you can’t change some security properties in the record at the PreOperation stage, so you need to do a workaround for this. The best one I found was simply to change the stage on which the plugin was running, instead of using PreOperation you should select PreValidation.
Hope it helps!