Using SQLiteAsyncConnection throwing a MissingMethodException
Asked Answered
P

1

7

First time using SQLite, opted for SQLite.net-pcl,

I have a PCL library, that I consume from my UWP app, my PCL library has the DBContext class :

public NewspaperDataContext(ISQLitePlatform sqLitePlatform, string applicationPath, string dataBaseName)
{
     _sqlConnection = new SQLiteAsyncConnection(()=> new SQLiteConnectionWithLock(sqLitePlatform, 
     new SQLite.Net.SQLiteConnectionString(Path.Combine(applicationPath, dataBaseName), storeDateTimeAsTicks: false)));

     CreateTableAsync(_sqlConnection, typeof(Article)).Result.Wait();
     CreateTableAsync(_sqlConnection, typeof(Author)).Result.Wait();
     CreateTableAsync(_sqlConnection, typeof(Category)).Result.Wait();
     CreateTableAsync(_sqlConnection, typeof(Group)).Result.Wait();

     var c = _sqlConnection.Table<Article>();
}

private async Task<Task> CreateTableAsync(SQLiteAsyncConnection asyncConnection, Type table)
{
     return asyncConnection.CreateTableAsync<Author>().ContinueWith((results) =>
     {
           Debug.WriteLine(!results.IsFaulted
           ? $"Error where creating the {nameof(table)} table !!"
           : $"Table {nameof(table)} created sucessfully!");
     });
}

I call the NewspaperDataContext from my UWP app like this :

private async void MainPage_OnLoaded(object sender, RoutedEventArgs e)
{            
    var n = new NewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");
}

In the NewspaperDataContext constructor at the line :

var c = _sqlConnection.Table<Article>();

A strange MissingMethodException is thrown saying :

An exception of type 'System.MissingMethodException' occurred in SQLite.Net.Async.dll but was not handled in user code

Additional information: Method not found: 'Void SQLite.Net.SQLiteConnectionString..ctor(System.String, Boolean, SQLite.Net.IBlobSerializer, SQLite.Net.IContractResolver)'.

Couldn't find anything related to this error in the internet, please can someone help.

Presidency answered 27/2, 2016 at 11:18 Comment(4)
This exception is thrown when there is an attempt to dynamically access a method that does not exist. I think the problem is possible that you create a method NewspaperDataContext which must have a return type, but there is no return value in your code. And you call this method somehow like creating a new instance of a class named NewspaperDataContext. If this method is void kind, can you please try to call this method with this code NewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");?Highhanded
Or, if there is a return value, would you please try to call this method like var n = NewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");? Sorry if I misunderstand your NewspaperDataContext method. But I think the problem may come with how you call this method.Highhanded
Did you get to the bottom of this issue? I am having a similar problemMask
Found out that it was resharper adding in an old package that caused my issue. github.com/oysteinkrog/SQLite.Net-PCL/issues/14Mask
S
0

The package sqlite-net-pcl should be added to only to PCL project. If you add it to any other platform such as Android, it will give this MethodMissingException. So, remove the package from other platforms as this package is required only for PCL project. I am giving this answer as I encountered the same issue and found the solution. I encountered this exception while developing apps using Xamarin.Forms.

Silvestro answered 15/10, 2019 at 10:13 Comment(1)
from here: "Important: You will need to add the NuGet package to both your .NET Standard library project and your platform-dependent app project." - so maybe version dependent?Desiccator

© 2022 - 2024 — McMap. All rights reserved.