在模拟器中运行的Xamarin.Android应用程序中使用Realm会抛出RealmFileAccessErrorException

时间:2016-05-15 12:09:37

标签: c# xamarin xamarin.android realm

我正在尝试将Realm添加到我的应用程序(Xamarin Android)。首先从模拟器开始(Xaamrin安卓播放器 - 带Android Lollipop的Nexus 5)。

Github Issue here

我的代码:

    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);
        }
        .......
   }

我得到的例外:

  

Realms.RealmFileAccessErrorException:不允许进行操作   Realms.NativeCommon.ExceptionThrower(IntPtr exceptionCode,IntPtr   utf8String,IntPtr stringLen)[0x0003b] in:0 at   (包装器本机到托管)Realms.NativeCommon:ExceptionThrower   (intptr,intptr,intptr)at(包装器托管到原生)   Realms.NativeSharedRealm:开放   (Realms.SchemaHandle,string,intptr,intptr,intptr,byte [],ulong)05-15   12:57:18.384 I / mono-stdout(5250):   Realms.RealmFileAccessErrorException:不允许操作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(包装器本机到管理)   Realms.NativeCommon:ExceptionThrower(intptr,intptr,intptr)05-15   12:57:18.385 I / mono-stdout(5250):at(包装器管理到原生)   Realms.NativeSharedRealm:开放   (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:\用户*** \源\回购\ AppName的\ MyApp的\活动\ SplashScreenActivity.cs:66   在Realms.Realm.GetInstance(Realms.RealmConfiguration config)   [0x0010c] in:0,Realms.Realm.GetInstance   (System.String databasePath)[0x00019] in:0 at   MyApp.Activities.SplashScreenActivity + d__4.MoveNext()   [0x00116] in   C:\用户*** \源\回购\ AppName的\ MyApp的\活动\ SplashScreenActivity.cs:66

如果我没有指定我得到的路径(var realm = Realm.GetInstance();):

  

System.ArgumentNullException:值不能为null。参数名称:   在System.Activator.CreateInstance中键入(System.Type类型,布尔值   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:   值不能为空。 05-15 13:05:05.257 I / mono-stdout(5474):   参数名称:类型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   在System.Activator.CreateInstance(System.Type type)[0x00000]中   /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/mscorlib/system/activator.cs:147   在Realms.Realm.CreateRealmObjectMetadata(System.Type   realmObjectType)[0x0001e] in:0 at   System.Linq.Enumerable.ToDictionary [TSource,TKEY的,TElement]   (IEnumerable 1 source, System.Func 2 keySelector,System.Func 2 elementSelector, IEqualityComparer 1 comparer)[0x0004d] in   /Users/builder/data/lanes/3053/a94a03b5/source/mono/external/referencesource/System.Core/System/Linq/Enumerable.cs:855   在System.Linq.Enumerable.ToDictionary [TSource,TKey,TElement]   (IEnumerable 1 source, System.Func 2 keySelector,System.Func 2 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.Func 2 keySelector, System.Func 2   elementSelector,IEqualityComparer 1 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] (IEnumerable 1 source,System.Func 2 keySelector, System.Func 2   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):在Realms.Realm..ctor   (Realms.SharedRealmHandle sharedRealmHandle,Realms.RealmConfiguration   config)[0x00037] in:0 05-15 13:05:05.257   I / mono-stdout(5474):在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:\用户*** \源\回购\ AppName的\ MyApp的\活动\ SplashScreenActivity.cs:66

该应用具有写入外部存储权限。 Realm和Fody nuget包正确安装,Fody编织器按预期存在..

使用带有Android 4.2的HTC One X也会出现相同的异常崩溃

1 个答案:

答案 0 :(得分:0)

上述尝试还有其他问题。 Realm中存在一个真正的错误,存储在外部存储上 - 请参阅问题https://github.com/realm/realm-dotnet/issues/554,这对调试来说很难。