2016-08-04 107 views
0

我想在MVVMCross UWP應用程序中使用SQLite;然而,當我試圖解決註冊的實例我的數據訪問層,我得到以下錯誤:在帶有MVVMCross的UWP中使用SQLite

Exception thrown: 'System.IO.FileLoadException' in MyApp.Core.dll

Additional information: Could not load file or assembly 'SQLite.Net, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

這裏是它崩潰:

private void AddProduct() 
 { 
    ICrudEntityDataAccess da = Mvx.Resolve<ICrudEntityDataAccess>(); 
     da.Create<Product>(Product); // Runtime error 
 } 

的UWP應用程序引用的NuGet包:

SQLite.Net.Platform.WinRT

和核心應用參考:

SQLite.Net.Core-PCL

而且

Sqlite.Net-PCL

在這裏註冊:

protected override void InitializeFirstChance() 
{ 
    base.InitializeFirstChance(); 

    MvxSimpleIoCContainer.Instance.RegisterSingleton<IPlatformSpecific>(
        new PlatformSpecific() 
        { 
            LocalFolderPath =  
                Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, 
                "db.sqlite") 
        }); 

    MvxSimpleIoCContainer.Instance.RegisterSingleton<ISQLitePlatform>(
     new SQLitePlatformWinRT()); 

顯然,我已經錯過了這方面的一個關鍵部分(我有關係猜測這是必需的,其項目的NuGet包。請有人指出我在正確的方向嗎?

回答

4

由於與iOS和Android不同,默認情況下不提供SQLite,因此您需要手動安裝並添加對SQLite for Universal Windows Platform包的引用。這實際上是一件好事,因爲你總是可以擁有最新最棒的版本!

here下載並安裝擴展 - 獲取通用Windows平臺標題下的最新版本標題。

重新啓動Visual Studio,在Solution Explorer中右鍵單擊您的UWP項目,選擇Add - Reference。在添加引用對話框窗口中選擇左側邊欄中的Universal Windows - Extensions,並在擴展名列表中選中框SQLite for Universal Windows Platform

這應該有望幫助解決您的問題。

+1

我試過了,最初沒有區別。我最終做的是刪除Nuget引用並重新添加它們;哪些工作。非常感謝。 –