Skip to content

Issue Creating Offline Database in MAUI on iOS - "Your platform does not support FileStream.Lock" #308

@FBonini22

Description

@FBonini22

Hello,

I am receiving the below exception when running my .NET MAUI app on any iOS device. The code works on Android devices.:

"Your platform does not support FileStream.Lock. Please set mode=Exclusive in your connnection string to avoid this error."

image

Here is the stack trace, it seems to be traced back to LiteDB:

 at LiteDB.StreamExtensions.CreateLockNotSupportedException(PlatformNotSupportedException innerEx)
  at LiteDB.StreamExtensions.<>c__DisplayClass4_0.<TryLock>b__0()
  at LiteDB.FileHelper.TryExec(Action action, TimeSpan timeout)
  at LiteDB.StreamExtensions.TryLock(FileStream stream, Int64 position, Int64 length, TimeSpan timeout)
  at LiteDB.FileDiskService.Lock(LockState state, TimeSpan timeout)
  at LiteDB.LiteEngine..ctor(IDiskService disk, String password, Nullable`1 timeout, Int32 cacheSize, Logger log, Boolean utcDate)
  at LiteDB.LiteDatabase.<>c__DisplayClass11_0.<.ctor>b__0()
  at LiteDB.LazyLoad`1[[LiteDB.LiteEngine, LiteDB, Version=4.1.4.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27]].get_Value()
  at LiteDB.LiteCollection`1.<Find>d__17[[Firebase.Database.Offline.OfflineEntry, Firebase, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
  at System.Linq.Enumerable.ToDictionary[OfflineEntry,String,OfflineEntry](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
  at System.Linq.Enumerable.ToDictionary[OfflineEntry,String,OfflineEntry](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
  at Firebase.Database.Offline.OfflineDatabase..ctor(Type itemType, String filenameModifier)

If I install the latest LiteDB from NuGet, I still get an error on the same line, but the debugger just can't resolve the symbols.

Below is the code I am running which is causing the issue:

public UserRootDatabase(string root, bool isOnline)
        {
            this.root = root;

            string userId = "TESTUSERID";

            clientOptions = new FirebaseOptions()
            {
                OfflineDatabaseFactory = (t, s) => **new OfflineDatabase(t, s),**
                AuthTokenAsyncFactory = async () =>
                {
                    return userId;
                }
            };

            string path = Config.Urls.FirebaseUrl.addPath("users").addPath(userId);

            firebaseClient = new FirebaseClient(path, clientOptions);

            rtdb = firebaseClient
                .Child(root)
                .AsRealtimeDatabase<T>(root,
                streamingOptions: StreamingOptions.None,
                initialPullStrategy: InitialPullStrategy.None,
                pushChanges: false);

The error occurs when rtdb is set to firebaseClient.Child(root)..... and the action "new OfflineDatabase(t, s) is then called.

Does anyone have an idea what could be causing an error like that? I'm going to try a couple more things and report back. Love this library, it's very helpful. TIA

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions