1
我有一些問題。這裏是我的代碼:例外,在WinRT加載文件後
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;
}
有沒有人知道如何解決這個問題?文件下載工作正常,下載後文件創建在一個文件夾中。
你爲什麼不只是檢查null? – i3arnon
這很簡單,因爲我應用程序首次啓動時需要此文件。 問題是爲什麼當應用第一次啓動時它爲空。 – ivamax9
可能是錯誤的「CheckExistingBase()」,使它返回「true」,即使該文件不存在?只是一個猜測 – har07