Automatic Code Error Diagnostics
- 3 minutes to read
#Code Diagnostics
The code analysis feature helps you detect XAF-specific errors in your code as you type. When a code analyzer finds rule violations, they are reported in the code editor (as a squiggle under the invalid code) and in the Error List window.
Note
Code analysis prerequisites and limitations:
- Only works with C# code
- Requires Visual Studio 2019 (or later) if you develop a .NET Framework project
#Enable Code Analysis
To turn on code analysis, add the DevExpress.ExpressApp.CodeAnalysis
NuGet package to all projects in your XAF solution.
#Disable Code Analysis
To turn off code analysis, remove the DevExpress.ExpressApp.CodeAnalysis
NuGet package from your project.
You can suppress warning messages as described in the following Microsoft article: How to suppress code analysis warnings.
// ...
namespace MySolution.Module.Controllers {
#pragma warning disable XAF0005 // XAF Controller classes should be public
class MyViewController : ViewController {
#pragma warning restore XAF0005 // XAF Controller classes should be public
// ...
}
}
#Project Diagnostics
The project analysis feature helps you detect XAF-specific errors in your .NET project. You can find information on rule violations in the Error List window.
These diagnostics are part of the DevExpress.ExpressApp.Design.NetCorePackage extension. They work when the extension is enabled and ensure the stable operation of the Model Editor.
#Supported Diagnostics
- XAF0001: Implement XPO business class constructors correctly
- XAF0002: XPO business class properties should not be overridden
- XAF0003: XPO business classes should be public
- XAF0004: Implement XAF controller constructors correctly
- XAF0005: XAF controller classes should be public
- XAF0006: Invalid target platform. Change the target platform to “Any CPU” in project or solution properties
- XAF0007: The Build Action property of the XAFML file must be set to Embedded resource
- XAF0008: The current Visual Studio version is not supported or .NET 6+ SDK is not installed
- XAF0009: Properties decorated with the RuleRequiredFieldAttribute should be of nullable or reference type
- XAF0010: Set the DelayedAttribute.UpdateModifiedOnly property to True
- XAF0011: Implement the delayed property correctly
- XAF0012: Avoid calling the XafApplication.CreateObjectSpace() method overload without the Type parameter
- XAF0013: Avoid reading the XafApplication.ConnectionString property
- XAF0014: The property with the Association attribute must have a correct unique pair
- XAF0015: Association must not have the Aggregated attribute if it is paired to the "many" end of the association
- XAF0016: Descendants of NonPersistentBaseObject and NonPersistentLiteObject must be decorated with the DomainComponent attribute
- XAF0017: Incompatible assemblies must not be added to the same project
- XAF0018: Avoid creating a new Session/UnitOfWork with parameterless constructors in XPO-based projects
- XAF0019: Apply ExplicitLoadingAttribute only to reference properties
- XAF0020: Avoid applying NonPersistentAttribute to properties without a public setter
- XAF0021: Create new controllers correctly
- XAF0022: Avoid using the ShowViewStrategy.ShowView method
- XAF0023: Do not implement IObjectSpaceLink in XPO classes
- XAF0024: Do not implement IXafEntityObject in XPO classes
- XAF0025: Use the corresponding XAF ORM-agnostic or Entity Framework attribute
- XAF0026: Use the supported version of EF Core packages
- XAF0027: Do not apply DomainComponentAttribute to an XPO business class
- XAF0028: Use the corresponding XPO attribute
- XAF0029: Use the enclosing property name in a method call
- XAF0030: Use the generic XPCollection<T> class, GetCollection<T> method, and AssociationAttribute without the type parameter to declare your association property
- XAF0031: Add the UseChangeTrackingProxies() call for automatic UI updates
- XAF0032: Use the explicit syntax to create an instance of the CriteriaOperator class