简体   繁体   中英

Using SQLite in a UWP with MVVMCross

I'm trying to use SQLite in an MVVMCross UWP app; however, as soon as I try to resolve the registered instance of my data access layer, I get the following error:

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)

Here is where it crashes:

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

The UWP app references the Nuget package:

SQLite.Net.Platform.WinRT

And the core app references:

SQLite.Net.Core-PCL

And

Sqlite.Net-PCL

The are registered here:

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());

Clearly I've missed a key part of this (I'm guessing with relation to which NuGet packages are required for which projects. Please could someone point me in the right direction?

Because SQLite is not provided by default in contrast to iOS and Android, you need to install and add a reference to the SQLite for Universal Windows Platform package manually. This is actually a great thing, because you can always have the latest and greatest version!

Download and install the extension from here - get the latest version under the Universal Windows Platform heading.

Restart Visual Studio, right click your UWP project in Solution Explorer, select Add - Reference . In the Add reference dialog window select Universal Windows - Extensions in the left sidebar and check the box for SQLite for Universal Windows Platform in the list of extensions.

This should hopefully help fix your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM