Skip to main content
A newer version of this page is available. .
All docs
V21.2
.NET Framework 4.5.2+

XAF0009: Properties decorated with the RuleRequiredFieldAttribute should be of nullable or reference type

Severity: Error

XAF requires that the properties decorated with the RuleRequiredFieldAttribute attribute must be of nullable or reference type. Otherwise, the validation rule does not work.

This diagnostic works only for XPO and EF Core business classes.

Examples

Invalid Code

using System; 
using DevExpress.Persistent.Validation; 

namespace TestApplication.Module.BusinessObjects { 
    public enum TitleOfCourtesy { Dr, Miss, Mr, Mrs,  Ms }; 

    public class TestClass { 
        public TestClass() { }

        int testValueProperty;
        // The property must be nullable
        //[RuleRequiredField] // Error: XAF0009 
        //public int TestValueProperty {get; set;} 

        TitleOfCourtesy testEnumProperty;
        // The property must be nullable or of reference type
        //[RuleRequiredField] // Error: XAF0009 
        //public TitleOfCourtesy TestEnumProperty {get; set;} 
    } 
} 

Valid Code

using System;
using DevExpress.Persistent.Validation;

namespace TestApplication.Module.BusinessObjects {

    public class ReferenceClass { }

    public class TestClass {
        public TestClass{} { }

        int? TestIntProperty;
        // The property that meets the requirements
        [RuleRequiredField]
        public int? TestIntProperty {get; set;}

        ReferenceClass testReferenceProperty;
        // The property that meets the requirements
        [RuleRequiredField]
        public ReferenceClass TestReferenceProperty {get; set;}
    }
}

How to Fix

Check the business object’s property declaration and ensure the property is of nullable or reference type.