Back to Devexpress

SessionCtorAbsentException Class

xpo-devexpress-dot-xpo-dot-exceptions-b94082c4.md

latest2.5 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public class SessionCtorAbsentException :
    Exception
vb
Public Class SessionCtorAbsentException
    Inherits 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.

csharp
public class OrderDetail : XPObject {
   public OrderDetail(Session session) : base(session) {
   }
   // ...
}
vb
Public Class OrderDetail
   Inherits XPObject
   Public Sub New(ByVal session As Session)
       MyBase.New(session)
   End Sub
   ' ...
End Class

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

SessionCtorAbsentException Members

DevExpress.Xpo.Exceptions Namespace