Path: redb/redb.Core/Exceptions/RedbPropsClassOlderException.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/RedbPropsClassOlderException.cs
----
using System;
using System.Collections.Generic;
namespace redb.Core.Exceptions;
///
/// A save refused because the Props class of this process is older than the scheme in the database: the stored
/// objects have values of fields a newer build of the class added under a nested class, an array or a dictionary
/// this class knows. Saving would replace that nested class or collection and delete those values. Nothing was
/// written.
///
///
/// A field a newer build added at the top level of the class is kept by the save and needs no refusal. The way out is
/// upgrading this process, or not saving these objects from it while old and new builds run side by side.
///
///
public class RedbPropsClassOlderException : Exception
{
/// The scheme of the objects.
public string SchemeName { get; }
/// The CLR type of the Props class this process saved with.
public Type PropsType { get; }
/// The fields the database has and the class lacks, as paths (HomeAddress.Country).
public IReadOnlyList UnknownFields { get; }
/// The version of the class this process saved with ().
public int ClassVersion { get; }
/// The version of the class the scheme was last synchronised with, as the database records it.
public int StoredVersion { get; }
public RedbPropsClassOlderException(string schemeName, Type propsType, IReadOnlyList unknownFields)
: base($"Saving objects of scheme '{schemeName}' with the class '{propsType.FullName}' would delete the values of " +
$"fields this class does not know: {string.Join(", ", unknownFields)}. A newer build of the class wrote them. " +
"Upgrade this process, or do not save these objects from it while old and new builds run side by side.")
{
SchemeName = schemeName;
PropsType = propsType;
UnknownFields = unknownFields;
}
///
/// The scheme was synchronised by a newer version of the class (),
/// which may have removed fields or changed their types: a save with this older class would write the old shape over
/// the new one, so it is refused as a whole.
///
public RedbPropsClassOlderException(string schemeName, Type propsType, int classVersion, int storedVersion)
: base($"Saving objects of scheme '{schemeName}' with the class '{propsType.FullName}' version {classVersion} is refused: " +
$"the scheme was synchronised by version {storedVersion} of the class, which may have removed fields or changed " +
"their types. Upgrade this process, or do not save these objects from it while old and new builds run side by side.")
{
SchemeName = schemeName;
PropsType = propsType;
UnknownFields = [];
ClassVersion = classVersion;
StoredVersion = storedVersion;
}
}