App crashes after inserting to SQLite database - "method arguments are incompatible"?

nmrl64nmrl64 ✭✭Member ✭✭

Hi everyone,
My app calls data from a web API in XML form, deserializes it with Newtonsoft.JsonConvert, and now I'm trying to get it to insert that data into a local SQLite database within the app. Here's my code:

`public MainPage()
{
InitializeComponent();
}

    public async void GetLocations()
    {
        var httpClient = new HttpClient();
        var response = await httpClient.GetStringAsync("my API url is here");
        var locations = JsonConvert.DeserializeObject<List<Location>>(response);
        SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
        conn.CreateTable<Location>();
        conn.Insert(locations);
        conn.Close();


    }

private void Button_Clicked(object sender, EventArgs e)
{
GetLocations();

        //await Navigation.PushAsync(new LocationPage());
    }
}`

So I've put breakpoints on the last three lines within the GetLocations method, and the first two go off perfectly; QuickWatch tells me all the data has been inserted successfully into the correct format. It's after that, presumably when I try to close the table connection (there are multiple tables of data I have to insert so I need to close each one at the end of each method) that the app crashes and I get "System.ArgumentException: 'method arguments are incompatible'". It does not hit the conn.Close(); breakpoint at all, it finishes the insert and then throws the exception. I'm thinking it may have to do with the method types, I'm not 100% sure on how to use async and void methods together properly.

Any help is greatly appreciated, thanks very much.

Sign In or Register to comment.