mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.62k stars 1.25k forks source link

[BUG] Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks #2318

Open Cruik opened 1 year ago

Cruik commented 1 year ago

Version LiteDB 5.0.16 / .Net6 Maui-Android

Describe the bug

When i try to get some collection of my db i get the following exception:

Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. (Parameter 'ticks')

Code to Reproduce

using var db = new LiteDatabase(await GetConnectionString());

var colConfig = db.GetCollection<ConfigurationEntity>("config");

Expected behavior Do not throw an exception and return the saved data

Screenshots/Stacktrace

(LobiLocalLiteDatabase)Error: System.ArgumentOutOfRangeException: Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. (Parameter 'ticks') at System.DateTime.ThrowTicksOutOfRange() at System.DateTime..ctor(Int64 ticks, DateTimeKind kind) at LiteDB.BufferSliceExtensions.ReadDateTime(BufferSlice buffer, Int32 offset) at LiteDB.Engine.HeaderPage..ctor(PageBuffer buffer) at LiteDB.Engine.LiteEngine..ctor(EngineSettings settings) at LiteDB.ConnectionString.CreateEngine() at LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper) at LiteDB.LiteDatabase..ctor(String connectionString, BsonMapper mapper) at Lobi.Local.Storage.LobiLocalLiteDatabase.LoadConfiguration() in D:\work\awagd\LOBI\New\src\Lobi.Local.Storage\LobiLocalLiteDatabase.cs:line 278 - Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. (Parameter 'ticks') at System.DateTime.ThrowTicksOutOfRange() at System.DateTime..ctor(Int64 ticks, DateTimeKind kind) at LiteDB.BufferSliceExtensions.ReadDateTime(BufferSlice buffer, Int32 offset) at LiteDB.Engine.HeaderPage..ctor(PageBuffer buffer) at LiteDB.Engine.LiteEngine..ctor(EngineSettings settings) at LiteDB.ConnectionString.CreateEngine() at LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper) at LiteDB.LiteDatabase..ctor(String connectionString, BsonMapper mapper) at Lobi.Local.Storage.LobiLocalLiteDatabase.LoadConfiguration() in D:\work\awagd\LOBI\New\src\Lobi.Local.Storage\LobiLocalLiteDatabase.cs:line 278

Additional context my db file is protected with an password. But the password only contains letters and numbers My LiteDb does not contain any datetime fields in this collections

dimplevador commented 1 year ago

@Cruik I faced same problem today. I don't know if you already found the solution or not. Posting it here for anyone else who faces similar issue.

The problem was that the creation date of the db file was corrupted for some reason. After I deleted the corrupted file, it worked fine. No error.