litedb-org/LiteDB · error · ArgumentNullException
oldName
Error message
oldName
What it means
ArgumentNullException thrown by LiteDatabase.RenameCollection(string oldName, string newName) when oldName is null, empty, or whitespace (IsNullOrWhiteSpace check). The source collection name must be concrete to locate it in the catalog before renaming.
Source
Thrown at LiteDB/Client/Database/LiteDatabase.cs:232
return this.GetCollectionNames().Contains(name, StringComparer.OrdinalIgnoreCase);
}
/// <summary>
/// Drop a collection and all data + indexes
/// </summary>
public bool DropCollection(string name)
{
if (name.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(name));
return _engine.DropCollection(name);
}
/// <summary>
/// Rename a collection. Returns false if oldName does not exists or newName already exists
/// </summary>
public bool RenameCollection(string oldName, string newName)
{
if (oldName.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(oldName));
if (newName.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(newName));
return _engine.RenameCollection(oldName, newName);
}
#endregion
#region Execute SQL
/// <summary>
/// Execute SQL commands and return as data reader.
/// </summary>
public IBsonDataReader Execute(TextReader commandReader, BsonDocument parameters = null)
{
if (commandReader == null) throw new ArgumentNullException(nameof(commandReader));
var tokenizer = new Tokenizer(commandReader);
var sql = new SqlParser(_engine, tokenizer, parameters);View on GitHub (pinned to f906a5f850)
Solutions
- Pass a concrete non-empty oldName: db.RenameCollection("customers", "clients").
- Verify oldName is non-empty and ideally exists (CollectionExists) before renaming.
- Guard dynamic oldName with IsNullOrWhiteSpace.
Example fix
// before
db.RenameCollection(oldName, newName); // oldName may be null
// after
if (!string.IsNullOrWhiteSpace(oldName) && !string.IsNullOrWhiteSpace(newName))
{
db.RenameCollection(oldName.Trim(), newName.Trim());
} Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrWhiteSpace(oldName) && db.CollectionExists(oldName.Trim()))
{
// safe to proceed toward rename
} Type guard
static bool IsValidCollectionName(string name) => !string.IsNullOrWhiteSpace(name);
Prevention
- Validate oldName is non-empty and exists before renaming.
- Keep argument order consistent (oldName, newName) to avoid swap bugs.
- Trim names from dynamic sources.
When it happens
Trigger: Calling db.RenameCollection(null, "new") or db.RenameCollection("", "new"); a source-name variable that is unset or empty.
Common situations: Renaming based on user/config input without validation; swapping argument order so the empty value lands in oldName; leftover placeholder.
Related errors
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/a86af0b34f305bda.
Report an issue: GitHub.