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:


Keep learning. Keep building.
Explore AI, agents & Microsoft technology.
I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.
Subscribe on YouTube →Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert
