How to debug text from text file with android emulator

Haviv Elbsz 1,886 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

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

Accepted answer
  1. Lloyd Sheen 1,376 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