DEVKIT1004 - phuocle/Dynamics-Crm-DevKit GitHub Wiki
This analyzer warns when using deprecated request/response classes from Microsoft.Crm.Sdk.Messages. These messages may be removed in future SDK versions and should be replaced with their modern equivalents.
The following messages are deprecated and should not be used. Most of these messages are for functionality that is no longer supported.
Using deprecated messages can cause:
- Future Compatibility Issues: Messages may be removed in future SDK versions
- Unsupported Functionality: Some deprecated messages represent discontinued features
- Technical Debt: Code using deprecated APIs requires refactoring later
- Support Limitations: Microsoft may not provide support for deprecated APIs
| Deprecated Message | Replacement |
|---|---|
SetStateRequest/Response |
Use Update request with statecode/statuscode |
ExecuteFetchRequest/Response |
Use RetrieveMultiple with FetchExpression |
AssociateEntitiesRequest/Response |
Use Associate request |
DisassociateEntitiesRequest/Response |
Use Disassociate request |
CompoundCreateRequest/Response |
Use individual Create requests |
CompoundUpdateRequest/Response |
Use individual Update requests |
The analyzer flags usages where:
-
newexpressions creating deprecated request/response types - Cast expressions
(DeprecatedType)obj -
asexpressionsobj as DeprecatedType
// Deprecated: SetStateRequest
var request = new SetStateRequest
{
EntityMoniker = new EntityReference("account", accountId),
State = new OptionSetValue(1),
Status = new OptionSetValue(2)
};
service.Execute(request);
// Deprecated: ExecuteFetchRequest
var fetchXml = @"<fetch><entity name='account'>...</entity></fetch>";
var request = new ExecuteFetchRequest { FetchXml = fetchXml };
var response = (ExecuteFetchResponse)service.Execute(request);// Modern: Use Update with statecode/statuscode
var account = new Entity("account", accountId)
{
["statecode"] = new OptionSetValue(1),
["statuscode"] = new OptionSetValue(2)
};
service.Update(account);
// Modern: RetrieveMultiple with FetchExpression
var fetchXml = @"<fetch><entity name='account'>...</entity></fetch>";
var result = service.RetrieveMultiple(new FetchExpression(fetchXml));- Identify Deprecated Usage: Find all usages of deprecated request types
- Use Modern Equivalent: Replace with the modern API as shown in the table above
- Test Thoroughly: Ensure the replacement works correctly in all scenarios
- var request = new SetStateRequest
- {
- EntityMoniker = entityRef,
- State = new OptionSetValue(0),
- Status = new OptionSetValue(1)
- };
- service.Execute(request);
+ var entity = new Entity(entityRef.LogicalName, entityRef.Id);
+ entity["statecode"] = new OptionSetValue(0);
+ entity["statuscode"] = new OptionSetValue(1);
+ service.Update(entity);If you have a legitimate need to suppress this warning:
#pragma warning disable DEVKIT1004
var request = new SetStateRequest { ... };
#pragma warning restore DEVKIT1004Or in .editorconfig:
[*.cs]
dotnet_diagnostic.DEVKIT1004.severity = suggestion| Property | Value |
|---|---|
| Rule ID | DEVKIT1004 |
| Category | DynamicsCrm.DevKit |
| Severity | Warning |
| Enabled by default | Yes |