我試圖找出正確的方法來加載我已經包含在我的包中的資源。還有一些類似於此的其他問題(例如Unable to access Asset files in Metro app),但是我希望避免在可能的情況下手動構建任意ms-appx:\\\
路徑。OpenStreamForReadAsync失敗,根目錄中的「參數不正確」
// The location of everything in my package.
StorageFolder packageLocation = Package.Current.InstalledLocation;
// The folder I want to load a file from
StorageFolder resources = await packageLocation.GetFolderAsync("Resources");
// I can successfully find the file, and then open a stream.
StorageFile file = await resources.GetFileAsync("Default.xml");
Stream streamFromFile = await file.OpenStreamForReadAsync();
// Also, I can just directly open a stream for the file from the folder.
Stream streamFromFolder = await resources.OpenStreamForReadAsync("Default.xml");
// Error: The parameter is incorrect
Stream streamFromRoot = await packageLocation.OpenStreamForReadAsync("Resources/Default.xml")
我試過很多的組合,包括./Resources/...
,/Resources/...
,ms-appx:///Resources/...
。爲什麼它不能從根文件夾中運行?
注意:我還沒有驗證,但我覺得我有其他'根'文件夾,如ApplicationData.Current.LocalFolder
相同的問題。
我在這個時刻感受到的完全和絕望的憤怒是沒有界限的。謝謝,並從UWP API中提取可疑錯誤。 –