I´m getting a System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.' when i try to connect to SQLite, but i don´t know how to solve this problem. My code:
public class SQLiteContactStore : IContactStore
{
private SQLiteAsyncConnection _connection;
public SQLiteContactStore(ISQLiteDb db)
{
_connection = db.GetConnection();
_connection.CreateTableAsync<Contact>();
}
public async Task<IEnumerable<Contact>> GetContactsAsync()
{
return await _connection.Table<Contact>().ToListAsync();
}
public async Task DeleteContact(Contact contact)
{
await _connection.DeleteAsync(contact);
}
public async Task AddContact(Contact contact)
{
await _connection.InsertAsync(contact);
}
public async Task UpdateContact(Contact contact)
{
await _connection.UpdateAsync(contact);
}
public async Task<Contact> GetContact(int id)
{
return await _connection.FindAsync<Contact>(id);
}
}
Exception comes in the line _connection = db.GetConnection();
My call stack shows this:
0x8 in APPv1.SQLiteContactStore..ctor at C:\Users\Fidel\Desktop\APPBUENAv1\APPv1\APPv1\Persistence\SQLiteContactStore.cs:16,13
that comes from:
public interface ISQLiteDb
{
SQLiteAsyncConnection GetConnection();
}
and this:
0xE in APPv1.Views.ContactsPage..ctor at C:\Users\Fidel\Desktop\APPBUENAv1\APPv1\APPv1\Views\ContactsPage.xaml.cs:12,13
that comes from:
public ContactsPage()
{
var contactStore = new SQLiteContactStore(DependencyService.Get<ISQLiteDb>());
var pageService = new PageService();
ViewModel = new ContactsPageViewModel(contactStore, pageService);
InitializeComponent();
}
Sorry, i´m a newbie...
Could you help me find the solution?
Thanks in advance.