Spent an afternoon debugging a Dataverse plug-in that looked like someone else was triggering it.

A PreOperation step on Create reported context.ParentContext != null. Easy conclusion: another plug-in must have kicked off this pipeline.

Wrong.

  • A single Create from the Web API did it.
  • So did a model-driven app save.
  • And the cleanest test, one stage-20 step on a table with zero stage-10 steps, still came back with a parent context.

In every case I tested on a current 9.2 org, PreOperation had a ParentContext for Create and Update. The platform creates the PreValidation-stage context as the parent of PreOperation. It exists whether or not a plug-in actually runs at stage 10, and whether the request came from a form, the Web API, or another plug-in.

What changes is what is inside it. With no PreValidation write, the parent bag held only platform keys like IsAutoTransact, AcceptLang and DefaultsAddedFlag. My key was not there.

So ParentContext is not a "was this triggered by another plug-in" flag.

If that is the real question, use context.Depth > 1, or inspect ParentContext.MessageName and PrimaryEntityName.

Where ParentContext does matter is shared variables. If a PreValidation step writes a value on Create, Update or Delete, PreOperation and PostOperation read it from context.ParentContext.SharedVariables, not from context.SharedVariables.

And check the key, not just the context:

if (context.ParentContext != null && context.ParentContext.SharedVariables.TryGetValue("my.key", out var value)) { // only true when stage 10 actually wrote it } 

Two different questions. Two different checks. Mixing them up cost me a few hours.