LiteDB throws unhandled exception when trying to open a shared connection

175 views Asked by At

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

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. The support/documentation for LiteDb is really poor, but managed to find a few odds and ends 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).

It does say this in the documentation:

"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? It just feels like LiteDb is getting more and more difficult to work with, so hope there's some workaround as would like to continue to support it.

14.01.24: EDIT

I have established this is a specific issue when running as part of a plugin for an app. I have narrowed the issue down to a specific method in LiteDb, but cannot explore the error any further. The LiteDb code that leads to an exception, I believ, is this:

internal ILiteEngine CreateEngine()
{
    EngineSettings settings = new EngineSettings
    {
        Filename = Filename,
        Password = Password,
        InitialSize = InitialSize,
        ReadOnly = ReadOnly,
        Collation = Collation
    };
    ...(Removed for clarity)
    if (Connection == ConnectionType.Shared)
    {
        return new SharedEngine(settings); // Error is thrown by this call
    }
    throw new NotImplementedException();
}

For some reason, I can't step into SharedEngine(settings) to try and drill down further...

0

There are 0 answers