Skip to main content

SessionCtorAbsentException Class

An exception that is thrown when a persistent class doesn’t have a constructor with a Session parameter.

Namespace: DevExpress.Xpo.Exceptions

Assembly: DevExpress.Xpo.v24.2.dll

Declaration

public class SessionCtorAbsentException :
    Exception

Remarks

The SessionCtorAbsentException exception occurs the following cases:

  • You create or load objects that don’t have a Session based constructor (MyObject(Session session)) and you use your own session (which is not Session.DefaultSession).
  • You create or load objects that don’t have a Session based constructor or default constructor (without parameters).

Best Practices

Always define a constructor with a Session parameter in your persistent objects. This allows you to avoid the SessionCtorAbsentException exception.

public class OrderDetail : XPObject {
   public OrderDetail(Session session) : base(session) {
   }
   // ...
} 

PersistentBase descendants are always associated with a Session. If you do not pass a Session instance in the constructor, XPO uses a default Session. This is a bad practice. Using the default Session can lead to mixing objects created with the default Session with ones created with another Session instance. XPO does not allow this, and throws the exception.

Inheritance

Object
Exception
SessionCtorAbsentException
See Also