Reference

Exceptions

The exceptions XOD throws, what causes each, and what to do about it.

Every XOD exception derives from Xod.XodException, so one catch (XodException) handles them all. They’re in the Xod namespace.

Xod.SecurityException is XOD’s own type, not System.Security.SecurityException. If both namespaces are imported, qualify it.

Data rules

Exception Thrown when What to do
ReservedPrimaryKeyException An insert uses a primary key that’s already taken. Use InsertOrUpdate, or check with Any first.
ReservedUniqueKeyException A [UniqueKey] value is already used by another row. Report the conflict to the user.
RequiredPropertyException A [Required] property is null or default. Set the value before writing.
ReservedChildException A child is added to or inserted with a parent while another parent already owns or lists it. Remove it from the first parent, update the new parent or parent key, or copy it.
MissingPrimaryKeyValueException A non-autonumber key part is at its type’s default (0, false, an enum’s first member, an empty Guid, or an empty or null string), or an update, delete or InsertOrUpdate by example sets only some parts of a composite key. Set every key part before writing.
MissingParentKeyException A child’s parent key can’t be resolved. Check the [ParentKey] names.
InvalidTextException A string holds a lone UTF-16 surrogate (invalid text) that no format can store unchanged. Fix the text before writing it.

Model mistakes

These come from the shape of a class, so they show up the first time you use it.

Exception Thrown when
PrimaryKeyDataTypeException A primary key isn’t a primitive, string, Guid or enum.
IndexDataTypeException An indexed property isn’t a primitive, number, string, DateTime or Guid, or carries [Crypto].
AutonumberDataTypeException AutoNumber is set on something other than a number or Guid.
AutonumberSeedException IdentitySeed or IdentityIncrement isn’t a valid whole number for the property’s type, is below 1, or is set on a Guid autonumber.
CryptoDataTypeException [Crypto] is on a property that isn’t a string.
PropertyKeyNameException A [ForeignKey] or [ParentKey] names a property that doesn’t exist.
ReservedKeyWordException A property uses a name XOD reserves.
AnonymousTypeException An anonymous type is stored. Use a named class.
XodException A property uses a type XOD can’t store or read back (Int128, Half, BigInteger, nint, tuples, custom structs, HashSet<T>, ArrayList, subclasses of List<T>, unconstructable map types, maps with non-scalar keys or values such as Dictionary<string, object>), or an object property / List<object> receives an unsupported value. The message names the property: mark it [NotMapped] or change its type (see Supported types).

Opening and storage

Exception Thrown when
DatabaseFileException The database doesn’t exist and InitialCreate is false, a file can’t be read or parsed, a page file named by a table is missing, an index entry’s row isn’t on its page, a legacy 2.0.x IDictionary<K, V> row is read, or a map’s stored culture is unavailable on this machine.
SecurityException The password is missing or wrong, isn’t 1 to 256 characters, Secure is called on a protected database, an encrypted property has been altered, an AES256 value is read or written without the password or PropertyEncryptionKey that protects its key, or Loose/ChangePassword would leave AES256 values unreadable.
DatabaseLockedException Another context or process (including the CLI or XodMigrator) already has the database open, or the file system provides no exclusive file lock. See Processes.
TransactionException A second transaction is started on a context, a finished transaction is used, a wait exceeds TransactionTimeoutMs, a password change or BeginTransaction/Commit/Rollback runs where refused, a commit meets another commit’s journal, or a failed commit can’t be undone. See Transactions.

XodMigrator.ConvertDatabase also throws ArgumentNullException for a missing argument and DirectoryNotFoundException for a missing source folder.

SQL

Sql throws XodSqlException. Its Code stays stable across releases; for syntax errors, Line and Column point to the token.

Code Thrown when
XQ001 The query doesn’t parse, calls an unknown function, or uses unsupported syntax (writes, WITH, UNION, window functions, right or full joins).
XQ002 No table has that name.
XQ003 A name is ambiguous (a class name in two namespaces, a column in two joined tables, or two columns mapping to one property in Sql<T>).
XQ004 No column, path or collection has that name.
XQ005 Type mismatch ('a' + 1), text that doesn’t parse as the compared type, or a value Sql<T> can’t convert losslessly.
XQ006 A column is neither grouped nor aggregated, or ORDER BY with DISTINCT names an unselected column.
XQ007 An INTEGER result overflows.
XQ010 Division by zero on INTEGER or DECIMAL (DOUBLE gives infinity or NaN).
XQ011 A scalar subquery returns more than one row.
XQ012 Missing parameter value, unused parameter value, or unsupported parameter type.

Non-fatal issues appear in SqlResult.Warnings: XQ008 (encrypted column read as NULL without its key), XQ013 (table or column without a recorded schema, read as text), and XQ014 (stored values that don’t parse as their column’s type, read as NULL).

Refusals and standard .NET exceptions

Some operational refusals throw a plain XodException explaining what to do:

Thrown when
A folder holds more than one database file, or the path names a new database file in a folder that already holds one (see One database per folder).
A write runs on a read-only context that holds no lock on the database (see Read-only folders).
An open finds crash leftovers in a folder where lock files can’t be opened or created.
Secure, ChangePassword or Loose is called while crash leftovers wait in the folder (reopen first).
A write or maintenance call runs from inside a read on the same thread, such as in a query’s predicate (see Writes from many threads).
A failed statement’s undo couldn’t complete; the context then refuses writes until reopened.
XodMigrator.ConvertDatabase targets a non-empty folder, a source with no database file, or a folder whose lock file can’t be opened.

Standard .NET exceptions thrown by XOD:

  • InvalidOperationException — calling Dispose() or changing the database password inside a BeforeAction or AfterAction handler, or calling Flush(), ClearCache()/ClearCaches() or GetStatistics() inside a handler in buffered mode or a transaction.
  • ArgumentOutOfRangeException — passing an undefined StorageFormat value to a context, XodMigrator or xod convert.
  • OverflowException — an autonumber exhausting its type’s range (or passing 2^24 on float / 2^53 on double).

Source on GitHub · Report a problem with this page