Unable to cast object of type 'LiteDB.EmptyPage' to type 'LiteDB.HeaderPage'
Closed the app and now it's happening.
at LiteDB.PageService.GetPage[T](UInt32 pageID)
at LiteDB.PageService.NewPage[T](BasePage prevPage)
at LiteDB.IndexService.AddNode(CollectionIndex index, BsonValue key, Byte level, IndexNode last)
at LiteDB.LiteEngine.UpdateDocument(CollectionPage col, BsonDocument doc)
at LiteDB.LiteEngine.<>c__DisplayClass29_0.<Update>b__0(CollectionPage col)
at LiteDB.LiteEngine.Transaction[T](String collection, Boolean addIfNotExists, Func`2 action)
at LiteDB.LiteCollection`1.Update(T document)
at MyAppAsync()
at System.Threading.Tasks.Task.Execute()
Are you using master branch version or 3.1.1 from Nuget?
Yes, version 3.1.0 from Nuget .. 3.1.1 was too slow so I downgraded ..
it's a UWP windows 10 app
I started getting InvalidCastException
Is there any way to fix it?
LiteDB.PageService.GetPage<System.__Canon>(Void* InstParam, UInt32 pageID) in at 0:0
LiteDB.TransactionService.Commit() in at 0:0
LiteDB.LiteEngine.Commit() in at 0:0
LiteDB.LiteEngine.Transaction<System.Int32>$catch$0() in at 0:0
LiteDB.LiteEngine.Insert(String collection, IEnumerable$1<$BsonDocument> docs) in at 0:0
LiteDB.LiteEngine.Insert(String collection, $BsonDocument doc) in at 0:0
LiteDB.LiteCollection$1<System.__Canon>.Insert(__Canon document) in at 0:0
this error occurs in some concurrency scenarios. I'm working on this to fix
I have added the option FileOptions.WriteThrough when opening the data file at 2017.6.13. The program runs very well utill the same problem appeared 3 days ago again.It's strange, isn't?
The version of LiteDB is 3.1.1.0 with a modify of adding the option FileOptions.WriteThrough. The threading model is single instance.
The first exception is
System.Threading.SynchronizationLockException: The write lock is being released without being held.
at System.Threading.ReaderWriterLockSlim.ExitWriteLock()
at LiteDB.LockService.
Then, It came after the program being restarted
System.InvalidCastException: Unable to cast object of type 'LiteDB.EmptyPage' to type 'LiteDB.HeaderPage'.
at LiteDB.PageService.GetPage[T](UInt32 pageID)
at LiteDB.PageService.NewPage[T](BasePage prevPage)
at LiteDB.PageService.GetFreePage[T](UInt32 startPageID, Int32 size)
at LiteDB.IndexService.AddNode(CollectionIndex index, BsonValue key, Byte level, IndexNode last)
at LiteDB.LiteEngine.InsertDocument(CollectionPage col, BsonDocument doc)
at LiteDB.LiteEngine.<>c__DisplayClass61_0.2 action)
at LiteDB.LiteEngine.Insert(String collection, IEnumerable1 docs)
at LiteDB.LiteCollection1.Insert(IEnumerable1 docs)
@mbdavid
Hi @lidanger, I'm working on it in "nojournal" branch. It's not finish, but you can check.
@mbdavid, that's good.I'll try.
Hi,
I have a similar issue, here is my stack trace:
System.InvalidCastException: 'Unable to cast object of type 'LiteDB.EmptyPage' to type 'LiteDB.IndexPage'.'
at LiteDB.PageService.GetPage[T](UInt32 pageID)
at LiteDB.PageService.GetFreePage[T](UInt32 startPageID, Int32 size)
at LiteDB.IndexService.AddNode(CollectionIndex index, BsonValue key, Byte level, IndexNode last)
at LiteDB.LiteEngine.InsertDocument(CollectionPage col, BsonDocument doc)
at LiteDB.LiteEngine.<>c__DisplayClass33_0.2 action)
at LiteDB.LiteEngine.Upsert(String collection, IEnumerable1 docs)
at LiteDB.LiteEngine.Upsert(String collection, BsonDocument doc)
at LiteDB.LiteCollection`1.Upsert(T document)
Thanks for investigating
Hi, I have a similar issue too , here is my stack trace: version is 4.1.1
System.InvalidCastException: Unable to cast object of type 'LiteDB.EmptyPage' to type 'LiteDB.DataPage'.
at LiteDB.PageService.GetPage[T](UInt32 pageID)
at LiteDB.QueryCursor.Fetch(TransactionService trans, DataService data, BsonReader bsonReader)
at LiteDB.LiteEngine.1.<Find>d__17.MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at xxxCache.<>c__DisplayClass29_0.
Hi @JasonGrass, I never got this error anymore (on v4.x). Can you use LiteDB.Demo project (inside LiteDB source) to make a replication of this error?
Here is the broken db file ,
But it can be read by using shell command.
I do not know how it been broken.


Same thing. Got this exception recently. Version is 4.1.1 (from Nuget)
System.InvalidCastException: Unable to cast object of type 'LiteDB.EmptyPage' to type 'LiteDB.IndexPage'.
at LiteDB.PageService.GetPage[T](UInt32 pageID)
at LiteDB.IndexService.<FindAll>d__13.MoveNext()
at LiteDB.QueryCursor.Fetch(TransactionService trans, DataService data, BsonReader bsonReader)
at LiteDB.LiteEngine.<Find>d__9.MoveNext()
at LiteDB.LiteEngine.<Find>d__13.MoveNext()
at LiteDB.LiteCollection`1.<Find>d__17.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
And here's the code producing it:
var chunk = liteCollection.Find(x => x.DocumentId == documentId, skip: allItems.Count, limit: chunkSize);
Hi @guys, this code/database already has broken and only with this I can replicate this broken problem. I never got this problem in v4.x. How are using LiteDB over concurrency? Are web/mobile or desktop app? How write operations are made? If possible, create a sample example using LiteDB.Demo project. I made this project just to catch this kind concurrency of problem.
Hi @mbdavid! Frankly speaking I'm not getting that issue since that moment and cannot reproduce it, though I tried. It is a desktop app (WPF) and I use write/update/delete records from different threads. Will keep you posted, if I face it again.
Hi @os-alan, if you could reproduce this error in v4 please send to me. After corrupt database I can test anymore.
Hey there - My team's product has been using LiteDB for a little while without seeing this problem. But just recently we updated from v3 something to v4.1.1.0, and also we switched over to using LiteDB's concurrency features (keeping a single instance of the database open and accessing it on multiple threads). Just after doing this, we started getting error reports from our users, with both this error message (https://github.com/StrangeLoopGames/EcoIssues/issues/5548) and a variety of similar messages (https://github.com/StrangeLoopGames/EcoIssues/issues/5610, https://github.com/StrangeLoopGames/EcoIssues/issues/5707).
It's possible the people who are seeing this had an existing .db/.journal file and it was upgraded to v4. I haven't been sure what to ask them. Would it be helpful for me to get their .db files and share them here?
Hi @MarjieAVolk, will be very helpfull if you can send me a copy of this corruped database to check. Did you know if this datafile was updated from v3? In v3 you don't have this problem?
Yes, in v3 I did not have the problem. But I also was not using concurrency in the same way. I will ask these people for their db files. Thanks.
Okay, I got one of the .db files that is seeing the error: Game.zip
This is the exact stack trace they reported:
Unable to cast object of type 'LiteDB.EmptyPage' to type 'LiteDB.HeaderPage'.
Stack:
at LiteDB.PageService.GetPage[T](UInt32 pageID)
at LiteDB.TransactionService.PersistDirtyPages()
at LiteDB.LiteEngine.Transaction[T](String collection, Boolean addIfNotExists, Func2 action)
at LiteDB.LiteEngine.Insert(String collection, BsonDocument doc, BsonType autoId)
at LiteDB.LiteCollection1.Insert(T document)
at Eco.Core.Utils.AtomicAction.SimpleAtomicAction.TryApply()
at Eco.Core.Utils.AtomicAction.MultiAtomicAction.TryApply()
at Eco.Core.Utils.AtomicAction.MultiAtomicAction.TryApply()
at Eco.Gameplay.Components.CraftingComponent.CreateWorkOrder(Player player, Recipe recipe, Int32 quantity)
Any updates on this? Did that file have the same issue?