我遇到了一些问题。这是我的代码:
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;
}
有人知道怎么解决吗?文件下载工作正常,下载后文件在文件夹中创建。
最佳答案
根据名称,我怀疑 SaveBaseFileAsync() 执行了一些异步操作。如果它是真的,你需要等待它,即称它为
await SaveBaseFileAsync(文件链接、文件夹、基本文件名);
关于c# - 异常,在 WinRT 中加载文件后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21246139/