Can't create tables with some reference to SQLiteNetExtensions in UWP Xamarin.Forms

Tecnopresley 96 Reputation points
2021-03-01T08:20:16.603+00:00

I am trying to implement the SQLiteNetExtensions.Async nuget in a Xamarin.Forms project but when I try to create a table with some reference to SQLiteNetExtensions I get the following exception when trying to create a table (only happens in UWP , in the rest of platforms it works well): Could not load file or assembly 'SQLite-net, Version=1.4.118.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the specified file.

I have 3 models: class, student and enrollment:

[Table("Classes")]
public class Class
{
    [PrimaryKey]
    [AutoIncrement]
    public int ClassId { get; set; }

    public string Title { get; set; }

    public string Description { get; set; }

    [ManyToMany(typeof(Enrollment))]
    public List<Student> Students { get; set; }
}

[Table("Students")]
public class Student
{
    [PrimaryKey]
    [AutoIncrement]
    public int StudentId { get; set; }

    public string LastName { get; set; }

    public string FirstName { get; set; }

    [ManyToMany(typeof(Enrollment))]
    public List<Class> Classes { get; set; }
}

[Table("Enrollments")]
public class Enrollment
{
    public int EnrollmentId { get; set; }

    [ForeignKey(typeof(Student))]
    public int StudentId { get; set; }

    [ForeignKey(typeof(Class))]
    public int ClassId { get; set; }
}

I use these versions:

SQLiteNetExtensions.Async version 2.1.0: https://www.nuget.org/packages/SQLiteNetExtensions.Async/

Xamarin.Forms version 5.0.0.2012

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
{count} votes

Accepted answer
  1. Tecnopresley 96 Reputation points
    2021-03-04T12:03:16.197+00:00

    I have managed to solve this problem, after downloading the source code of SQLite-Net Extensions from the original repository I have proceeded to update the target framework from the version .NET Standard 1.1 to .NET Standard 2.0 of the SQLiteNetExtensions project and SQLiteNetExtensionsAsync from the original repository and I have created a local nuget of those two projects which I have imported into my project.

    I have also posted a pull request in the original repository to integrate the fix: https://bitbucket.org/twincoders/sqlite-net-extensions/pull-requests/32/fix-crash-in-uwp-for-xamarinforms


0 additional answers

Sort by: Most helpful