You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: XrmPluginCore.SourceGenerator/rules/XPC3004.md
+21-1Lines changed: 21 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ This rule reports when `LocalPluginContext` is used as the `TService` type argum
10
10
11
11
This typically happens when migrating from the legacy `RegisterPluginStep<T>` API and mistakenly using `RegisterStep<TEntity, LocalPluginContext>` instead of the correct DI-based approach.
12
12
13
-
## ❌ Example of violation
13
+
## ❌ Example of violation (explicit type argument)
14
14
15
15
```csharp
16
16
publicclassContactPlugin : Plugin
@@ -28,6 +28,26 @@ public class ContactPlugin : Plugin
28
28
}
29
29
```
30
30
31
+
## ❌ Example of violation (implicit — method group with LocalPluginContext parameter)
32
+
33
+
```csharp
34
+
publicclassContactPlugin : Plugin
35
+
{
36
+
publicContactPlugin()
37
+
{
38
+
// XPC3004: Execute(LocalPluginContext) cannot be converted to Action<IExtendedServiceProvider>
39
+
RegisterStep<Contact>(
40
+
EventOperation.Update,
41
+
ExecutionStage.PostOperation,
42
+
Execute);
43
+
}
44
+
45
+
privatevoidExecute(LocalPluginContextcontext) { }
46
+
}
47
+
```
48
+
49
+
This form is also detected because `RegisterStep<TEntity>` expects `Action<IExtendedServiceProvider>`, and a method group or lambda whose parameter is `LocalPluginContext` is not assignable to that delegate type. The code fails to compile with a delegate mismatch error. Use `RegisterPluginStep<T>` if you need to keep `LocalPluginContext` as the entry point.
50
+
31
51
## ✅ How to fix (interim — keep LocalPluginContext logic)
32
52
33
53
Use `RegisterPluginStep<T>` which correctly wraps the `LocalPluginContext`:
0 commit comments