litedb-org/LiteDB · error · ArgumentNullException
newName
Error message
newName
What it means
ArgumentNullException thrown by LiteDatabase.RenameCollection(string oldName, string newName) when newName is null, empty, or whitespace (IsNullOrWhiteSpace check, checked after oldName). The destination collection name must be concrete; an empty target is rejected before the engine attempts the rename.
Source
Thrown at LiteDB/Client/Database/LiteDatabase.cs:233
}
/// <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);
var reader = sql.Execute();View on GitHub (pinned to f906a5f850)
Solutions
- Pass a concrete non-empty newName: db.RenameCollection("customers", "clients").
- Validate newName is non-empty and does not already collide with an existing collection.
- Guard dynamic newName with IsNullOrWhiteSpace.
Example fix
// before
db.RenameCollection(oldName, newName); // newName may be null
// after
if (!string.IsNullOrWhiteSpace(oldName) && !string.IsNullOrWhiteSpace(newName)
&& !db.CollectionExists(newName.Trim()))
{
db.RenameCollection(oldName.Trim(), newName.Trim());
} Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrWhiteSpace(newName) && !db.CollectionExists(newName.Trim()))
{
// newName is valid and does not collide; safe to rename
} Type guard
static bool IsValidCollectionName(string name) => !string.IsNullOrWhiteSpace(name);
Prevention
- Validate newName is non-empty and not already in use before renaming.
- Trim destination names from dynamic sources.
- Confirm the rename returned true to detect oldName-missing/newName-collision cases.
When it happens
Trigger: Calling db.RenameCollection("customers", null) or db.RenameCollection("customers", ""); a destination-name variable that is unset or whitespace.
Common situations: Renaming to a config/user-supplied name without validation; copy-paste leaving the second argument empty; whitespace-only target name.
Related errors
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/bb9aa0827585872b.
Report an issue: GitHub.