A method was called at an unexpected time
You need to wait for the async method to complete. So you could use the new await as one option:
var files = await myStorageFolder.GetFilesAsync();
You might want to check the documentation on dealing with async methods here.
If you don't want to use the async
keyword (in my case, the code was inside a property, so async
wasn't an option), you can use a TaskAwaiter
instead, by chaining these two methods:
var folder = Package.Current.InstalledLocation.GetFolderAsync("folderName").GetAwaiter().GetResult();
This won't throw a InvalidOperationException
nor cause a deadlock.