-
Notifications
You must be signed in to change notification settings - Fork 16
DEVKIT1021
PhuocLe edited this page Jun 20, 2026
·
2 revisions
This analyzer detects catch blocks inside plugin or workflow activity code that do not call ITracingService.Trace. Exception traces are essential when diagnosing Dataverse plugin and workflow failures, especially in sandboxed environments.
📚 Use ITracingService in Plug-ins
Catch blocks without tracing can cause:
- Lost exception details: The original stack trace or contextual data may not be visible
- Slow debugging: Failures require reproduction instead of reading trace logs
- Poor supportability: Production issues are harder to diagnose
- Generic user errors: Users may only see a simplified platform message
The analyzer flags catch blocks that:
- Are inside a plugin or workflow activity class
- Do not contain an invocation of
Trace(...)on an expression typed asMicrosoft.Xrm.Sdk.ITracingService
public class AccountPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
try
{
DoWork();
}
catch (Exception ex)
{
// ❌ No trace is written before throwing
throw new InvalidPluginExecutionException("Account processing failed.", ex);
}
}
}public class AccountPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var tracingService = (ITracingService)serviceProvider
.GetService(typeof(ITracingService));
try
{
DoWork();
}
catch (Exception ex)
{
// ✅ Exception details are captured in plugin trace logs
tracingService.Trace($"Account processing failed: {ex.Message}");
tracingService.Trace(ex.ToString());
throw new InvalidPluginExecutionException("Account processing failed.", ex);
}
}
}- Get
ITracingServicefrom the service provider - Call
tracingService.Trace(...)inside each catch block - Include enough context to diagnose the failing operation
- Re-throw with
InvalidPluginExecutionExceptionwhen the error should be shown through Dataverse
catch (Exception ex)
{
+ tracingService.Trace(ex.ToString());
throw new InvalidPluginExecutionException("Operation failed.", ex);
}Trace output is captured by Dataverse when plug-in trace logging is enabled:
- Open Plug-in Trace Log
- Filter by plugin assembly, type, message, or correlation id
- Review the
MessageBlockfield for trace output
Suppress only when a catch block intentionally handles an exception without producing Dataverse trace output.
#pragma warning disable DEVKIT1021
catch (ExpectedException)
{
// Intentionally ignored
}
#pragma warning restore DEVKIT1021Or in .editorconfig:
[*.cs]
dotnet_diagnostic.DEVKIT1021.severity = none- DEVKIT1011 - Use InvalidPluginExecutionException in plug-ins and workflow activities
- DEVKIT1012 - Consider using ITracingService in plug-ins
- DEVKIT1017 - Avoid Console output in plug-ins
| Property | Value |
|---|---|
| Rule ID | DEVKIT1021 |
| Category | DynamicsCrm.DevKit |
| Severity | Warning |
| Enabled by default | Yes |