mbdavid / LiteDB

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

Application crash at DropCollection #2460

Closed InesCodMon closed 3 weeks ago

InesCodMon commented 3 months ago

Version v5.0.18 and v5.0.19 /MacOS/.NET Standard 2.0

Describe the bug I want to clean up the database (remove all collections and their content). But an error occurs when DropCollection is called the first time.

Code to Reproduce public void CleanupDatabase() { IEnumerable listOfCollections = _db.GetCollectionNames(); foreach (string item in listOfCollections) { Console.WriteLine("COLLECTION" + item.ToString()); _db.DropCollection(item); } }

Expected behavior All collections should be removed. The above code is expected to work the same as it does in version v5.0.17.

Screenshots/Stacktrace The below error occurs when the DropCollection method is called.

LiteDB.LiteException: The current thread already contains an open transaction. Use the Commit/Rollback method to release the previous transaction. at LiteDB.Engine.LiteEngine.DropCollection (System.String name) [0x0003e] in :0 at LiteDB.LiteDatabase.DropCollection (System.String name) [0x00013] in :0

fabiorme commented 2 months ago

I encountered the same error while migrating from v5.0.17 to v5.0.19

LiteDB.LiteException: The current thread already contains an open transaction. Use the Commit/Rollback method to release the previous transaction. at LiteDB.Engine.LiteEngine.DropCollection (System.String name) [0x0003e] in <757508dac4404cdea3f8947f089148e1>:0 at LiteDB.LiteDatabase.DropCollection (System.String name) [0x00013] in <757508dac4404cdea3f8947f089148e1>:0

I tried both Commit and Rollback before performing the drop, but it didn't work. I think for now I'll revert back to version 17.

GreenIreland commented 2 months ago

I encountered the same error while migrating from v5.0.17 to v5.0.19

Same.

JKamsker commented 3 weeks ago

Thank you for reporting this issue.

This issue has been resolved in the latest version of LiteDB. Please update to the latest version of LiteDB to resolve this issue. If the issue persists, please let us know.