litedb-org/LiteDB · critical · NotSupportedException

BSON type not supported

Error message

BSON type not supported

What it means

Thrown by BufferReader.ReadValue when the BSON type byte read from a data stream does not match any known type code (0x01 Double, 0x02 String, 0x03 Document, 0x04 Array, 0x05 Binary, 0x07 ObjectId, 0x08 Boolean, 0x09 DateTime, 0x0A Null, 0x10 Int32, 0x12 Int64, 0x13 Decimal, 0x64 Vector, 0xFF MinKey, 0x7F MaxKey). This is a NotSupportedException, indicating a corrupt or foreign data stream. Note: the throw is unreachable in normal flow (dead code after the if-else chain), but fires if the type byte falls through.

Source

Thrown at LiteDB/Engine/Disk/Serializer/BufferReader.cs:555

            }
            else if (type == 0x13) // Decimal
            {
                return this.ReadDecimal();
            }
            else if (type == 0xFF) // MinKey
            {
                return BsonValue.MinValue;
            }
            else if (type == 0x7F) // MaxKey
            {
                return BsonValue.MaxValue;
            }
            else if (type == 0x64) // Vector
            {
                return this.ReadVector();
            }

                throw new NotSupportedException("BSON type not supported");
        }

        #endregion

        public void Dispose()
        {
            _source?.Dispose();
        }
    }
}

View on GitHub (pinned to f906a5f850)

Solutions

  1. Restore the database from a known-good backup.
  2. Verify the file was produced by a compatible LiteDB version; upgrade if reading a newer-format file.
  3. Run the LiteDB repair/recovery tool if available for your version.
  4. Ensure no external process is writing to the .db file concurrently.
Defensive patterns

Strategy: try-catch

Try / catch

try { /* read/parse from database file */ }
catch (NotSupportedException ex) when (ex.Message == "BSON type not supported")
{ /* database corruption or version mismatch; restore backup or upgrade */ }

Prevention

When it happens

Trigger: Reading a corrupted database file or a data file produced by an incompatible/other BSON library. A buffer position error causing misalignment of the type byte. Truncated or partially-written data pages.

Common situations: Database file corruption from improper shutdown, disk failure, or concurrent access by non-LiteDB tooling. Version mismatch where a newer BSON type code is read by an older LiteDB build. Manual tampering with the .db file.

Related errors


AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13). Data as JSON: /api/errors/044e4a7525d95488. Report an issue: GitHub.