mbdavid / LiteDB

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

[BUG] Unhandled exception when trying to open a shared conneciton in .net Framework 4.8 #2393

Open stigzler opened 10 months ago

stigzler commented 10 months ago

Version I am developing on .net Framework 4.8 with LiteDb 5.0.17.0.

Describe the bug When I try to instantiate a database connection with:

Connection = new LiteDatabase("Filename=C:\\temp\\data.ldb;Connection=Shared");

I get the following error:

System.MissingMethodException
  HResult=0x80131513
  Message=Method not found: 'Void System.Threading.Mutex..ctor(Boolean, System.String, Boolean ByRef, System.Security.AccessControl.MutexSecurity)'.
  Source=LiteDB
  StackTrace:
   at LiteDB.SharedEngine..ctor(EngineSettings settings)
   at LiteDB.ConnectionString.CreateEngine()
   at LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper)

It works fine if I omit the connection specification. I managed to find a few odds and ends for this through google, but couldn't match to my particular use case. However, it looks like something to do with .net versions and Mutex (which I'm not familiar with)??

I did find this in your docs:

"The Shared mode only works in .NET implementations that provide named mutexes. Its multi-process capabilities will only work in platforms that implement named mutexes as system-wide mutexes."

However, I have no idea what this means, whether this applies to Framework 4.8 or not and indeed what to do as a result.

Any suggestions?

Code to Reproduce

Connection = new LiteDatabase("Filename=C:\\temp\\data.ldb;Connection=Shared");

Expected behavior Shared Connection is opened

fil-at-werma commented 8 months ago

I've opened a Bounty of 50 rep for an exhaustive answer to this on Stackoverflow: https://stackoverflow.com/questions/77539735/litedb-throws-unhandled-exception-when-trying-to-open-a-shared-connection

expiring in 7 days.