How to debug text from text file with android emulator

Haviv Elbsz 2,071 Reputation points
2023-01-12T09:36:39.89+00:00

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

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Lloyd Sheen 1,486 Reputation points
    2023-01-12T12:53:14.32+00:00

    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");
    
            try
            {
                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;
        }
    
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.