Warning
This rule reports when a plugin class that inherits from Plugin has explicit constructors but no parameterless constructor. The Dynamics 365/Dataverse framework instantiates plugins using parameterless constructors, so plugins must have one to function correctly at runtime.
public class AccountPlugin : Plugin
{
// XPC2001: Plugin class 'AccountPlugin' has no parameterless constructor
public AccountPlugin(string config) // Only has constructor with parameters
{
RegisterStep<Account, IAccountService>(
EventOperation.Update,
ExecutionStage.PostOperation,
nameof(IAccountService.HandleUpdate))
.WithPreImage(x => x.Name);
}
}Add a parameterless constructor to the plugin class:
public class AccountPlugin : Plugin
{
// Parameterless constructor required by Dynamics 365
public AccountPlugin()
{
RegisterStep<Account, IAccountService>(
EventOperation.Update,
ExecutionStage.PostOperation,
nameof(IAccountService.HandleUpdate))
.WithPreImage(x => x.Name);
}
// Additional constructor for testing or configuration is allowed
public AccountPlugin(string config) : this()
{
// Additional configuration
}
}Alternatively, if you only need one constructor, use a parameterless one:
public class AccountPlugin : Plugin
{
public AccountPlugin()
{
RegisterStep<Account, IAccountService>(
EventOperation.Update,
ExecutionStage.PostOperation,
nameof(IAccountService.HandleUpdate))
.WithPreImage(x => x.Name);
}
}- Runtime requirement: The Dynamics 365/Dataverse plugin execution pipeline creates plugin instances using
Activator.CreateInstance(), which requires a parameterless constructor - Code generation: When this rule is violated, the source generator will not generate type-safe image wrapper classes for the plugin
- Deployment failure: Plugins without parameterless constructors will fail to execute at runtime with an error about missing constructor
If your class has no explicit constructors defined, the C# compiler automatically provides a default parameterless constructor, so this rule will not be triggered.