Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Sequence contains no elements #1956

Closed
deccer opened this issue Mar 13, 2021 · 1 comment
Closed

[BUG] Sequence contains no elements #1956

deccer opened this issue Mar 13, 2021 · 1 comment
Labels

Comments

@deccer
Copy link

deccer commented Mar 13, 2021

Version
5.0.10 (NuGet)

OS
Windows 10 1803 (17134)

Describe the bug
InvalidOperationException is thrown when trying to create a litedb with a tempfilename (.tmp extension)
Stepping into source reveals the following line as the source of the exception.
LiteEngine.cs:783 PageBuffer buffer = this._disk.ReadFull(FileOrigin.Data).First<PageBuffer>();

However, when using any other extension ie Path.ChangeFileExtension(Path.GetTempFileName, ".db") makes the code work. I am not exactly sure whats going on as the litedb code doesnt seem to care about file extensions at all.

Code to Reproduce

public static void Main(string[] args)
{
    var db = new LiteDB.Database(Path.GetTempFileName());
    db.Dispose();
}

Expected behavior
No Exception being thrown, and an empty db file being created with whatever metadata necessary to exist with 0 collections inside

Screenshots/Stacktrace

System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   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 LiteDbDisposeRepro.Program.Main(String[] args) in C:\Users\deccer\RiderProjects\LiteDbDisposeRepro\LiteDbDisposeRepro\Program.cs:line 12

Additional context
I was actually trying to reproduce a bug where .Dispose-ing of the db engine takes ~5s every time, because of some string.Join showing up in the profiler

@lbnascimento
Copy link
Contributor

@deccer This happened because LiteDB failed to initialize zero-byte files. It was fixed in the master, so it should be working now. In the meantime, in case you're stuck with the latest release, just delete the zero-byte temp file before opening it with LiteDB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants