How to debug text from text file with android emulator

Haviv Elbsz 481 Reputation points

Hi all. I need to debug text from a text file and the emulator don't open a file from my computer so I can debug my app exit with null reference exception and I want to locate the location. how I can do that with the emulator. Thank you very much

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
905 questions
No comments
{count} votes

Accepted answer
  1. Lloyd Sheen 781 Reputation points

    You need to add the file to your solution. Then make sure the file Build Action is MauiAsset.

    Then you can use the file as the following , the filename is a constant in this case.

        public async static Task<string> GetHistTeams()
            string txt;
            string mainDir = FileSystem.Current.AppDataDirectory;
            var fullpath = Path.Combine(mainDir, "theTeams.json");
                Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync("theTeams.json");
                StreamReader reader = new StreamReader(fileStream);
                txt = reader.ReadToEnd();
            catch (Exception e)
                var i = 1;
                return string.Empty;
            return txt;
    No comments

0 additional answers

Sort by: Most helpful