Path: redb/redb.Core/Exceptions/RedbCollectionKindChangeException.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Exceptions/RedbCollectionKindChangeException.cs
----
using System;
namespace redb.Core.Exceptions;
///
/// A scheme sync refused because a property changed its collection kind (a single value, an array or a dictionary) while
/// the structure still holds values. The stored rows have the shape of the old kind and the new class would read them
/// wrong: a single value would come back as an empty array, an array as null, the positions of an array as dictionary
/// keys. The values would then be lost at the next save. Nothing is converted. The sync stops at this property; the
/// properties synced before it are complete, and the scheme keeps its stored version, so the next start tries again.
///
public class RedbCollectionKindChangeException : Exception
{
/// The scheme of the property.
public string SchemeName { get; }
/// The property as its structure names it.
public string PropertyName { get; }
/// The structure that holds the values.
public long StructureId { get; }
/// The kind stored for the structure: "single value", "array" or "dictionary".
public string StoredKind { get; }
/// The kind the class declares.
public string DeclaredKind { get; }
public RedbCollectionKindChangeException(string schemeName, string propertyName, long structureId, string storedKind, string declaredKind)
: base($"The sync of scheme '{schemeName}' is refused: the property '{propertyName}' (structure {structureId}) is stored " +
$"as {Article(storedKind)} and the class declares {Article(declaredKind)}, while the database holds values of it. " +
"redb does not convert values between collection kinds, and the new class would read the stored ones wrong. " +
"Give the new shape a new property name (the old one keeps its values until it is removed), or move the " +
"values by hand before the upgrade and remove the old ones.")
{
SchemeName = schemeName;
PropertyName = propertyName;
StructureId = structureId;
StoredKind = storedKind;
DeclaredKind = declaredKind;
}
private static string Article(string kind) => kind == "array" ? "an array" : "a " + kind;
}