2016-09-25 36 views
1

您好我在Android中調試時使用Azure移動服務脫機存儲時遇到此異常。它雖然使用Windows時工作正常。Xamrin表單System.TypeInitializationException

下面是代碼,就基於所述tod0list示例

static StaffManager defaultInstance = new StaffManager(); 
    MobileServiceClient client; 

    IMobileServiceSyncTable<Staff> staffTable; 

    private StaffManager() 
    { 
     client = new MobileServiceClient(Constants.ApplicationURL); 

      var store = new MobileServiceSQLiteStore("localstore1.db"); 
      store.DefineTable<Staff>(); 

      this.client.SyncContext.InitializeAsync(store); 

      this.staffTable = client.GetSyncTable<Staff>(); 

    } 

這是例外:

System.TypeInitializationException:類型初始化爲 'OrchardApp.StaffManager' 引發了異常。 D/Mono(1684):DllImport試圖加載:'/system/lib/liblog.so'。DllImport試圖加載:'/system/lib/liblog.so'。 09-26 11:05:48.991 D/Mono(1684):DllImport加載庫'/system/lib/liblog.so'。 09-26 11:05:48.991 D/Mono(1684):DllImport正在搜索:'/system/lib/liblog.so'('/system/lib/liblog.so')。 09-26 11:05:48.991 D/Mono(1684):搜索'__android_log_print'。 09-26 11:05:48.991 D/Mono(1684):探測'__android_log_print'。 09-26 11:05:48.991 D /單音(1684):找到'__android_log_print'。我的MonoDroid(1684):System.TypeInitializationException:'OrchardApp.StaffManager'的類型初始值設定項會拋出一個例外。 ---> Microsoft.WindowsAzure.MobileServices.SQLiteStore.SQLiteException:執行SQLite命令時出錯:'無法打開數據庫文件'。 09-26 11:05:48.991 I/MonoDroid(1684):at Microsoft.WindowsAzure.MobileServices.SQLiteStore.SQLitePCLRawHelpers.VerifySQLiteResponse(Int32 result,Int32 expectedResult,SQLitePCL.sqlite3 db)[0x00024] in:0 09-26 11/05:48.991 I/MonoDroid(1684):在Microsoft.WindowsAzure.MobileServices.SQLiteStore.SQLitePCLRawHelpers.GetSqliteConnection(System.String文件名)[0x0000d]中:0 09-26 11:05:48.991 I/MonoDroid(1684) ):在Microsoft.WindowsAzure.MobileServices.SQLiteStore.MobileServiceSQLiteStore..ctor(System.String文件名)[0x00039]中:0 09-26 11:05:48.991 I/MonoDroid(1684):在OrchardApp.StaffManager..ctor ()[] 0x0001e]在C:\ OPAC \ OrchardApp \ OrchardApp \ OrchardApp \ Services \ StaffManager.cs中:27 09-26 11:05:48.991 I/MonoDroid(1684):在OrchardApp.StaffManager..cctor 0x00000]在C:\ OPAC \ OrchardApp \ OrchardApp \ OrchardApp \ Services中\ StaffManager.cs:16 09-26 11:05:48.991 I/MonoDroid(1684):---內部異常堆棧跟蹤結束--- 09-26 11:05:48.991 I/MonoDroid(1684):在OrchardApp.TodoList..ctor()[0x0000f]在C:\ OPAC \ OrchardApp \ OrchardApp \ OrchardApp \ Views \ TodoList.xaml.cs:18 09-26 11:05:48.991 I/MonoDroid(1684):at OrchardApp.HomePage + < < -ctor> b__0_1> d.MoveNext()[0x0000f]在C:\ OPAC \ OrchardApp \ OrchardApp \ OrchardApp \ Views \ HomePage.xaml.cs中:26 09-26 11:05:48.991 I/MonoDroid(1684):---從以前的位置拋出異常的堆棧跟蹤結束--- 09-26 11:05:48.991 I/MonoDroid(1684):在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in/Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionse rvicescommon.cs:143 09-26 11:05:48.995 I/MonoDroid(1684):在System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0(System.Object狀態)在[/ Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018 09-26 11:05:48.995 I/MonoDroid(1684):at Android.App.SyncContext + c__AnonStorey0。 <> m__0()[0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:09-26 11:05 :48.995 I/MonoDroid(1684):位於/Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/src/中的Java.Lang.Thread + RunnableImplementor.Run()[0x0000b] Java.Lang/Thread.cs:36 09-26 11:05:48。995 I/MonoDroid(1684):在Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv,IntPtr native__this)中的[0x00009]位於/Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/ (包裝動態方法)System.Object:578fa2b5-486e- 424f-9b2b-bb0dcaf1a772(intptr,intptr) 09-26 11:05:49.003 D/Mono(1684):DllImport搜索:'__Internal'('(null)')。 09-26 11:05:49.003 D/Mono(1684):搜索'java_interop_jnienv_throw'。 09-26 11:05:49.003 D/Mono(1684):探測'java_interop_jnienv_throw'。 09-26 11:05:49.003 D /單聲道(1684):找到'java_interop_jnienv_throw'。 發生未處理的異常。

+0

要獲得答案,您必須指定例外(消息及其出現位置)。以下是關於調試Xamarin的一些提示: http://xamariniac.hlinteractive.se/index.php/2016/09/22/debugging-xamarin-and-cross-platform-exceptions/ –

+0

嗨,我已添加異常詳細信息 –

+1

某些建議降級Azure移動服務(在他們的情況下爲2.1.1)。 https://forums.xamarin.com/discussion/78936/microsoft-azure-mobile-client-sqlitestore-upgraded-to-3-0-get-error-unable-to-open-database-file –

回答

0

與PCL項目3.0.0版類似的問題,我曾與this解決方法

PCL項目App.cs

 public static string Path = "MyLocalStore.db"; 

的Android項目MainActivity.cs NEL方法方法的OnCreate

 //Call this in each platform before intializing your Mobile Client 
     SQLitePCL.Batteries.Init(); 

     App.Path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), App.Path); 

     if (!File.Exists(App.Path)) 
     { 
      File.Create(App.Path).Dispose(); 
     } 
解決

終於

 var store = new MobileServiceSQLiteStore(App.Path); 
相關問題