To raise an error in the plugin code, we use InvalidPluginExecutionException.

For example:

throw new InvalidPluginExecutionException("Plugin has run. Code will stop executing.");

The code runs in the Execute function of the plugin code. For example:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; namespace Carl.AssociateDisassociate
public class AssociateDisassociate : IPlugin
public void Execute(IServiceProvider serviceProvider)         {             throw new InvalidPluginExecutionException("Plugin has run. Code will stop executing.");        

The code will display the error and stop executing:

If you register the code on the Pre-Operation it will prevent the rest of the CRM code from running:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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