在带有MVVMCross的UWP中使用SQLite

在带有MVVMCross的UWP中使用SQLite

问题描述:

我想在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包。请有人指出我在正确的方向吗?

由于与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引用并重新添加它们;哪些工作。非常感谢。 –