question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] System.Exception: LiteDB ENSURE: empty page must be defined as empty type

See original GitHub issue

Version LiteDB v5.0.10 .NET Standard 2.1 Xamarin.Forms v5.0.0.2012

Describe the bug The database seems to get corrupted when I insert data. Here are multiple examples:


System.Exception: LiteDB ENSURE: empty page must be defined as empty type
  at LiteDB.Constants.ENSURE (System.Boolean conditional, System.String message) [0x0002a] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.NewPage[T] () [0x000a3] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.GetFreeDataPage (System.Int32 bytesLength) [0x00081] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService+<>c__DisplayClass3_0+<<Insert>g__source|0>d.MoveNext () [0x00052] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.BufferWriter..ctor (System.Collections.Generic.IEnumerable`1[T] source) [0x00029] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService.Insert (LiteDB.BsonDocument doc) [0x0005d] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.InsertDocument (LiteDB.Engine.Snapshot snapshot, LiteDB.BsonDocument doc, LiteDB.BsonAutoId autoId, LiteDB.Engine.IndexService indexer, LiteDB.Engine.DataService data) [0x00094] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine+<>c__DisplayClass7_0.<Insert>b__0 (LiteDB.Engine.TransactionService transaction) [0x00076] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.AutoTransaction[T] (System.Func`2[T,TResult] fn) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.Insert (System.String collection, System.Collections.Generic.IEnumerable`1[T] docs, LiteDB.BsonAutoId autoId) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.LiteCollection`1[T].Insert (System.Collections.Generic.IEnumerable`1[T] entities) [0x00027] in <8e1f39e9bcf3452cab277acc385e2e12>:0 


System.Exception: LiteDB ENSURE: empty page must be defined as empty type
  at LiteDB.Constants.ENSURE (System.Boolean conditional, System.String message) [0x0002a] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.NewPage[T] () [0x000a3] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.GetFreeDataPage (System.Int32 bytesLength) [0x00081] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService+<>c__DisplayClass3_0+<<Insert>g__source|0>d.MoveNext () [0x00052] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.BufferWriter..ctor (System.Collections.Generic.IEnumerable`1[T] source) [0x00029] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService.Insert (LiteDB.BsonDocument doc) [0x0005d] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.InsertDocument (LiteDB.Engine.Snapshot snapshot, LiteDB.BsonDocument doc, LiteDB.BsonAutoId autoId, LiteDB.Engine.IndexService indexer, LiteDB.Engine.DataService data) [0x00094] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine+<>c__DisplayClass7_0.<Insert>b__0 (LiteDB.Engine.TransactionService transaction) [0x00076] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.AutoTransaction[T] (System.Func`2[T,TResult] fn) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.Insert (System.String collection, System.Collections.Generic.IEnumerable`1[T] docs, LiteDB.BsonAutoId autoId) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.LiteCollection`1[T].Insert (System.Collections.Generic.IEnumerable`1[T] entities) [0x00027] in <8e1f39e9bcf3452cab277acc385e2e12>:0 


System.Exception: LiteDB ENSURE: empty page must be defined as empty type
  at LiteDB.Constants.ENSURE (System.Boolean conditional, System.String message) [0x0002a] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.NewPage[T] () [0x000a3] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.GetFreeDataPage (System.Int32 bytesLength) [0x00081] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService+<>c__DisplayClass3_0+<<Insert>g__source|0>d.MoveNext () [0x00052] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.BufferWriter..ctor (System.Collections.Generic.IEnumerable`1[T] source) [0x00029] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService.Insert (LiteDB.BsonDocument doc) [0x0005d] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.InsertDocument (LiteDB.Engine.Snapshot snapshot, LiteDB.BsonDocument doc, LiteDB.BsonAutoId autoId, LiteDB.Engine.IndexService indexer, LiteDB.Engine.DataService data) [0x00094] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine+<>c__DisplayClass7_0.<Insert>b__0 (LiteDB.Engine.TransactionService transaction) [0x00076] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.AutoTransaction[T] (System.Func`2[T,TResult] fn) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.Insert (System.String collection, System.Collections.Generic.IEnumerable`1[T] docs, LiteDB.BsonAutoId autoId) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.LiteCollection`1[T].Insert (T entity) [0x0002e] in <8e1f39e9bcf3452cab277acc385e2e12>:0 


System.AggregateException: One or more errors occurred. (LiteDB ENSURE: empty page must be defined as empty type) ---> System.Exception: LiteDB ENSURE: empty page must be defined as empty type
  at LiteDB.Constants.ENSURE (System.Boolean conditional, System.String message) [0x0002a] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.NewPage[T] () [0x000a3] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.GetFreeDataPage (System.Int32 bytesLength) [0x00081] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService+<>c__DisplayClass3_0+<<Insert>g__source|0>d.MoveNext () [0x00052] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.BufferWriter..ctor (System.Collections.Generic.IEnumerable`1[T] source) [0x00029] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService.Insert (LiteDB.BsonDocument doc) [0x0005d] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.InsertDocument (LiteDB.Engine.Snapshot snapshot, LiteDB.BsonDocument doc, LiteDB.BsonAutoId autoId, LiteDB.Engine.IndexService indexer, LiteDB.Engine.DataService data) [0x00094] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine+<>c__DisplayClass7_0.<Insert>b__0 (LiteDB.Engine.TransactionService transaction) [0x00076] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.AutoTransaction[T] (System.Func`2[T,TResult] fn) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.Insert (System.String collection, System.Collections.Generic.IEnumerable`1[T] docs, LiteDB.BsonAutoId autoId) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.LiteCollection`1[T].Insert (T entity) [0x0002e] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.Exception: LiteDB ENSURE: empty page must be defined as empty type
  at LiteDB.Constants.ENSURE (System.Boolean conditional, System.String message) [0x0002a] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.NewPage[T] () [0x000a3] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.Snapshot.GetFreeDataPage (System.Int32 bytesLength) [0x00081] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService+<>c__DisplayClass3_0+<<Insert>g__source|0>d.MoveNext () [0x00052] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.BufferWriter..ctor (System.Collections.Generic.IEnumerable`1[T] source) [0x00029] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.DataService.Insert (LiteDB.BsonDocument doc) [0x0005d] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.InsertDocument (LiteDB.Engine.Snapshot snapshot, LiteDB.BsonDocument doc, LiteDB.BsonAutoId autoId, LiteDB.Engine.IndexService indexer, LiteDB.Engine.DataService data) [0x00094] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine+<>c__DisplayClass7_0.<Insert>b__0 (LiteDB.Engine.TransactionService transaction) [0x00076] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.AutoTransaction[T] (System.Func`2[T,TResult] fn) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.Engine.LiteEngine.Insert (System.String collection, System.Collections.Generic.IEnumerable`1[T] docs, LiteDB.BsonAutoId autoId) [0x00055] in <8e1f39e9bcf3452cab277acc385e2e12>:0 
  at LiteDB.LiteCollection`1[T].Insert (T entity) [0x0002e] in <8e1f39e9bcf3452cab277acc385e2e12>:0 

Code to Reproduce Unfortunately I cannot share code, since I could not reproduce it easily in a test project and I cannot share my business work. I can just say that I’m pretty sure I’m not doing any kind of magic with LiteDB; I’m using it basically just to store data (delete all, re insert, get all)

Expected behavior No exception.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:36 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
mbdavidcommented, Feb 22, 2021

Hi guys, this ensure error avoid/detect corruption state. I will review this operations to try reproduce this error.

1reaction
eyal7773commented, Aug 11, 2022

Hi, I also have this problem. It’s very important to us to arrive to solution. I can share my db file. and also my code.

When using DeleteAll() we got LiteDB ENSURE: page type must be data page error.

One more thing :

if I try to delete by raw query from the LiteDbStudio - so it works ! BUT, same raw query, from code, using Execute - failed.

Can you help please ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

LiteDB ENSURE: empty page must be defined as empty type
[BUG] System.Exception: LiteDB ENSURE: empty page must be defined as empty type.
Read more >
LiteDB Transaction Error - PowerShell Universal
System.Exception: LiteDB ENSURE: transaction must be active to rollback (current state: Disposed) at LiteDB.Constants.
Read more >
LiteDB FileStreamFactory.GetStream (System.Boolean ...
I'm having this issue on Litedb with Android app (built with xamarin forms),. Version: 5.0.11. Note: I ensure that there is only one ......
Read more >
List of Error Codes and Solutions
Below is a list of commonly-encountered error messages and related information. The errors are sorted by number or code (if one is ...
Read more >
Collections - LiteDB :: A .NET embedded NoSQL database
LiteCollection is a generic class that is used to manage collections in LiteDB. Each collection must have a unique name: Contains only letters,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found