Hololens Load File to Stream

I’m having an issue trying to read a basic text file and load the data to my app. I’m using IL2CPP to build the app, and pre-processors to surround the async parts.

I’m using this as my read.

public void ReadString() {
  string s;
#if !UNITY_EDITOR && UNITY_METRO
  try {
    using (Stream stream = OpenFileForRead(ApplicationData.Current.RoamingFolder.Path, "filename.txt")) {
      byte[] data = new byte[stream.Length];
      stream.Read(data, 0, data.Length);
      s = Encoding.ASCII.GetString(data);
    }
  }
  catch (Exception e) {
    Debug.Log(e);
  }
#endif
  return s;
}

private static Stream OpenFileForRead(string folderName, string fileName) {
  Stream stream = null;
#if !UNITY_EDITOR && UNITY_METRO
  Task task = new Task(
    async () => {
      StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(folderName);
      StorageFile file = await folder.GetFileAsync(fileName);
      stream = await file.OpenStreamForReadAsync();
    });
  task.Start();
  task.Wait();
#endif
  return stream;
}

I can’t seem to build this with the OpenStreamForReadAsync().

Why not just use File.ReadAllText?

does it work on the hololens?

It sure does if you use IL2CPP.