I’ve been working with a LiteDatabase for a .NET MAUI mobile app, the idea behind the app is to pull everything from a live database and store it in a local database.
Only recently have I been getting the error “LiteDB ENSURE: empty page must be defined as empty type”, and this is happening intermittently after the local database collection has been cleared using
using (LiteDatabase db = new LiteDatabase(UserDatabasePath))
{
return db.DropCollection(collectionName);
}
And t
hen reset using
List<CompressorModel> compressors = JsonConvert.DeserializeObject<List<CompressorModel>>(data.Result);
using (LiteDatabase db = new LiteDatabase(UserDatabasePath))
{
ILiteCollection<CompressorModel> hCollection = db.GetCollection<CompressorModel>(collectionName);
//hCollection.Insert(compressors);
}
(We have a few dozen different types of collections, this is just an example of one)
And intermittently I will get that error in a try/catch block with random collections, Compressors being the most recent one and the one that is giving me the most issue. For reference, here’s the stack trace
at LiteDB.Constants.ENSURE(Boolean conditional, String message)
at LiteDB.Engine.Snapshot.NewPageIndexPage
at LiteDB.Engine.IndexService.CreateIndex(String name, String expr, Boolean unique)
at LiteDB.Engine.CollectionService.Add(String name, CollectionPage& collectionPage)
at LiteDB.Engine.CollectionService.Get(String name, Boolean addIfNotExists, CollectionPage& collectionPage)
at LiteDB.Engine.Snapshot..ctor(LockMode mode, String collectionName, HeaderPage header, UInt32 transactionID, TransactionPages transPages, LockService locker, WalIndexService walIndex, DiskReader reader, Boolean addIfNotExists)
at LiteDB.Engine.TransactionService.g__create|43_0(<>c__DisplayClass43_0& )
at LiteDB.Engine.TransactionService.CreateSnapshot(LockMode mode, String collection, Boolean addIfNotExists)
at LiteDB.Engine.LiteEngine.<>c__DisplayClass7_0.b__0(TransactionService transaction)
at LiteDB.Engine.LiteEngine.AutoTransaction[Int32](Func2 fn) at LiteDB.Engine.LiteEngine.Insert(String collection, IEnumerable
1 docs, BsonAutoId autoId)
at LiteDB.LiteCollection1[[MAUIGMSApp.Models.CompressorModel, MAUIGMSApp, Version=2.3.3.0, Culture=neutral, PublicKeyToken=null]].Insert(IEnumerable
1 entities)
at MAUIGMSApp.ViewModels.DatabaseService.GetCompressors(SyncService ss) in C:GIT – MAUI FieldsyncGMS.FieldSync.MobileMAUIGMSAppViewModelsDatabaseService.cs:line 1800
I assume that the error has something to do with null values based on the error message, but I can’t seem to find anything to support that. I’ve looked through my data quite a few times, and for compressors at least it will allow me to enter a few of them, if I try to only enter about a quarter of whats in our database, but every time I try to pinpoint one compressor that is causing these issues it seems to just accept the one that I think is being the problem when I track it down to a specific one
For other collections it’s normally fixed after I drop all the database and re-pull, but not for compressors