Bug Report B134095
Visible to All Users

Exception occurs when checking a RuleObjectExists for an object that doesn't have a default property

created 16 years ago

I'm trying to get my validation on the run since hours. I want to use the RuleObjectExists Rule to detect if there are any objects in my db that contain the given value. (It's an order number duplicate check.)
I'm always getting a "Object reference not set to an instance of an object." exception. So I tried the code that is availlable in the docu. (Department at CustomMessageTemplate Property) Unfortunately I got the same exception:
An exception occurs while validating an object:
Exception: 'Object reference not set to an instance of an object.'
Rule Id: 'DevExpress.Persistent.Validation.RuleObjectExists_Titan.Module.Web.BusinessClasses.Department'
Rule Type: 'DevExpress.Persistent.Validation.RuleObjectExists'
Target Object: 'Titan.Module.Web.BusinessClasses.Department(00000000-0000-0000-0000-000000000000)'
My code:
    [DefaultClassOptions]
    [RuleObjectExists("",DefaultContexts.Save,"Office=205",InvertResult = true,
   CriteriaEvaluationBehavior=PersistentCriteriaEvaluationBehavior.BeforeTransaction,
   MessageTemplateMustExist = "The objects that satisfy the … criteria must not exist")]
    public class Department : BaseObject
    {
        public Department(Session session) : base(session) { }
        private string office;
        public string Office
        {
            get { return office; }
            set { SetPropertyValue("Office", ref office, value); }
        }
    }
Steps to Reproduce:

  1. Start Application
  2. Create New Department with Number 1
  3. Create New Department with Number 205
  4. Create New Department with Number 205
    Actual Results:
    An exception occurs while validating an object:
    Exception: 'Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.'
    Rule Id: 'DevExpress.Persistent.Validation.RuleObjectExists_tbr_validationtest.Module.Department'
    Rule Type: 'DevExpress.Persistent.Validation.RuleObjectExists'
    Target Object: 'tbr_validationtest.Module.Department(00000000-0000-0000-0000-000000000000)'
    Expected Results:
    Normal Rule Behaviour
Comments (1)
CP CP
Constantine P (DevExpress) 16 years ago

    Hello Torsten,
    This bug is fixed in the next version of the suite. To avoid this exception in the current version, you can decorate your class with the DefaultProperty attribute:

    C#
    [DefaultProperty("Office")] public class Department : BaseObject { ...

    Alternatively, you can just add the 'Name' property to your class, so that this property is used as the default one:

    C#
    public class Department : BaseObject { ... public string Name { get { return "Office# " + Office; } } }

    Thanks,
    Constantin

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.