Skip to content

Latest commit

 

History

History
79 lines (62 loc) · 2.55 KB

File metadata and controls

79 lines (62 loc) · 2.55 KB

XPC2001: No parameterless constructor found

Severity

Warning

Description

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.

❌ Example of violation

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);
    }
}

✅ How to fix

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);
    }
}

Why this matters

  1. Runtime requirement: The Dynamics 365/Dataverse plugin execution pipeline creates plugin instances using Activator.CreateInstance(), which requires a parameterless constructor
  2. Code generation: When this rule is violated, the source generator will not generate type-safe image wrapper classes for the plugin
  3. 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.

See also