0
votes

I'm trying to add Realm to my app (Xamarin Android). Starting with emulator first (Xaamrin android player - Nexus 5 with Android Lollipop).

Github Issue here

My code:

    protected override async void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.MyActivitylayout);
        ....
        try
        {
            var path = AndroidIoHelper.CreateFileInAppFolder(AndroidIoHelper.GetAppDataFolder(), "tlm_db", "realm");

            var realm = Realm.GetInstance(path);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
        .......
   }

Exception I'm getting:

Realms.RealmFileAccessErrorException: Operation not permitted at Realms.NativeCommon.ExceptionThrower (IntPtr exceptionCode, IntPtr utf8String, IntPtr stringLen) [0x0003b] in :0 at (wrapper native-to-managed) Realms.NativeCommon:ExceptionThrower (intptr,intptr,intptr) at (wrapper managed-to-native) Realms.NativeSharedRealm:open (Realms.SchemaHandle,string,intptr,intptr,intptr,byte[],ulong) 05-15 12:57:18.384 I/mono-stdout( 5250): Realms.RealmFileAccessErrorException: Operation not permitted 05-15 12:57:18.384 I/mono-stdout( 5250): at Realms.NativeCommon.ExceptionThrower (IntPtr exceptionCode, IntPtr utf8String, IntPtr stringLen) [0x0003b] in :0 05-15 12:57:18.384 I/mono-stdout( 5250): at (wrapper native-to-managed) Realms.NativeCommon:ExceptionThrower (intptr,intptr,intptr) 05-15 12:57:18.385 I/mono-stdout( 5250): at (wrapper managed-to-native) Realms.NativeSharedRealm:open (Realms.SchemaHandle,string,intptr,intptr,intptr,byte[],ulong) 05-15 12:57:18.385 I/mono-stdout( 5250): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x0010c] in :0 05-15 12:57:18.385 I/mono-stdout( 5250): at Realms.Realm.GetInstance (System.String databasePath) [0x00019] in :0 05-15 12:57:18.385 I/mono-stdout( 5250): at MyApp.Activities.SplashScreenActivity+d__4.MoveNext () [0x00116] in C:\Users***\Source\Repos\AppName\MyApp\Activities\SplashScreenActivity.cs:66 at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x0010c] in :0 at Realms.Realm.GetInstance (System.String databasePath) [0x00019] in :0 at MyApp.Activities.SplashScreenActivity+d__4.MoveNext () [0x00116] in C:\Users***\Source\Repos\AppName\MyApp\Activities\SplashScreenActivity.cs:66

If I don't specify path I'm getting (var realm = Realm.GetInstance();):

System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00006] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/activator.cs:205 05-15 13:05:05.257 I/mono-stdout( 5474): System.ArgumentNullException: Value cannot be null. 05-15 13:05:05.257 I/mono-stdout( 5474): Parameter name: type 05-15 13:05:05.257 I/mono-stdout( 5474): at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00006] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/activator.cs:205 05-15 13:05:05.257 I/mono-stdout( 5474): at System.Activator.CreateInstance (System.Type type) [0x00000] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/activator.cs:147 at System.Activator.CreateInstance (System.Type type) [0x00000] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/activator.cs:147 at Realms.Realm.CreateRealmObjectMetadata (System.Type realmObjectType) [0x0001e] in :0 at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (IEnumerable1 source, System.Func2 keySelector, System.Func2 elementSelector, IEqualityComparer1 comparer) [0x0004d] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/System.Core/System/Linq/Enumerable.cs:855 at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (IEnumerable1 source, System.Func2 keySelector, System.Func2 elementSelector) [0x00000] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/System.Core/System/Linq/Enumerable.cs:847 at Realms.Realm..ctor (Realms.SharedRealmHandle sharedRealmHandle, Realms.RealmConfiguration config) [0x00037] in <filename unknown>:0
at Realms .Realm.GetInstance (Realms.RealmConfiguration config) [0x00171] in <filename unknown>:0 at MyApp.Activities.SplashScreenActivity+<OnCreate>d__4.MoveNext () [0x00116] in C:\Users\***\Source\Repos\AppName\MyApp\Activities\SplashScreenActivity.cs:66 05-15 13:05:05.257 I/mono-stdout( 5474): at Realms.Realm.CreateRealmObjectMetadata (System.Type realmObjectType) [0x0001e] in <filename unknown>:0 05-15 13:05:05.257 I/mono-stdout( 5474): at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (IEnumerable
1 source, System.Func2 keySelector, System.Func2 elementSelector, IEqualityComparer1 comparer) [0x0004d] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/System.Core/System/Linq/Enumerable.cs:855 05-15 13:05:05.257 I/mono-stdout( 5474): at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (IEnumerable1 source, System.Func2 keySelector, System.Func2 elementSelector) [0x00000] in /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/System.Core/System/Linq/Enumerable.cs:847 05-15 13:05:05.257 I/mono-stdout( 5474): at Realms.Realm..ctor (Realms.SharedRealmHandle sharedRealmHandle, Realms.RealmConfiguration config) [0x00037] in :0 05-15 13:05:05.257 I/mono-stdout( 5474): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00171] in :0 05-15 13:05:05.257 I/mono-stdout( 5474): at MyApp.Activities.SplashScreenActivity+d__4.MoveNext () [0x00116] in C:\Users***\Source\Repos\AppName\MyApp\Activities\SplashScreenActivity.cs:66

The app has Write external storage permission. Realm and Fody nuget packages installed properly, Fody weavers are present as expected..

It also crashes with same exception using HTC One X with Android 4.2

1
This question seems to have spawned a discussion here: github.com/realm/realm-dotnet/issues/542, in case anyone else hits this. - Tayschrenn

1 Answers

0
votes

The above attempt had other issues. There is a real bug currently in Realm with storage on external storage - see the issue https://github.com/realm/realm-dotnet/issues/554 which is proving awkward to debug.