dataverse-plugins
Dataverse Plugins
CRITICAL RULES
-
MOST DANGEROUS: Never use instance fields for per-request state. Plugin instances are cached by the platform and reused across requests. Multiple concurrent requests execute on the SAME instance simultaneously. Storing
this._context,this._orgService, or any per-request data in instance fields causes race conditions and data corruption — intermittent, hard to reproduce, and catastrophic. All per-request state MUST be local variables insideExecute(). The constructor runs once (or after step registration changes) — not per request. -
Swallowing
OrganizationServiceFaultsilently breaks the transaction. Any catch-and-continue after an org service call failure leaves the transaction in an invalid state. The next service call throws a misleading error that appears to originate from an entirely different plugin, making root cause analysis extremely difficult. Always rethrow asInvalidPluginExecutionException. -
Set HTTP timeout explicitly — default is 100 seconds. Without
HttpClient.Timeout, a stuck external call can consume the entire 2-minute operation budget. Set timeout ≤ 15 seconds. Also setconnection.KeepAlive = falseand force sync execution with.GetAwaiter().GetResult()—awaitcauses deadlocks in .NET 4.6.2 plugin context. -
Secure Configuration is NOT exported with solutions.
SecureConfigvalues are stripped on export. They must be manually re-entered in every target environment after import. The #1 source of "works in dev, silent failure in prod" with configured plugins. Document all required Secure Config values in your solution README. -
Always specify filtering attributes on Update registrations. A plugin on Update with no filtering attributes fires for every field change on every Update call — including automated system updates. In high-volume environments this multiplies execution count dramatically. Register only for the specific columns your logic reads.
-
Throw
InvalidPluginExecutionExceptionfor all user-facing errors. Any other exception surfaces asIsvUnExpectedand exposes the raw stack trace and exception type to users. Wrap at the top ofExecute(): always catch, always rethrow asInvalidPluginExecutionException. -
PreValidation runs BEFORE security checks. Your plugin executes for users who may not yet have been authorized. Doing work (logging, reads, external calls) in PreValidation means unauthorized users trigger that work before the platform rejects them.
-
Async PostOperation plugins fire in parallel. Multiple async plugins on the same message all start simultaneously. If they all update the same related record, concurrent update conflicts occur intermittently. Use queue-based patterns or a single async plugin that coordinates work when multiple handlers touch the same parent records.