Question

I'm having some problems. Here's my code:

private async void SetCollectionForGame()
{
    maincollection = new Dictionary<string, string>();

    bool statebase = await CheckExistingBase();

    if (statebase)
    {
        //If file exists...
        basefile = await folder.GetFileAsync(basefilename);
    }
    else
    {
        //If file does not exist...
        SaveBaseFileAsync(filelink, folder, basefilename);
        basefile = await folder.GetFileAsync(basefilename);
    }
    string content = String.Empty;
    content = await FileIO.ReadTextAsync(basefile, Windows.Storage.Streams.UnicodeEncoding.Utf8);
    //When the app first starts, I get an exception on the next line,
    //because the variable "content" is null.
    maincollection = JsonConvert.DeserializeObject<CollectionModel>(content).collection;
}

Does anybody know how to solve this? File downloading works fine, and after the download the file was created in a folder.

Was it helpful?

Solution

Based on the name, I suspect that SaveBaseFileAsync() executes some async operations. If it's true, you need to await it, i.e. call it as

await SaveBaseFileAsync(filelink, folder, basefilename);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top