NET MAUI V8.0 App - Issues with XAML page and await client.GetObjectAsync() for AWS S3 bucket

Riffy 276 Reputation points


I am working on a NET MAUI V8 App that uses AWS S3 for file access. However, I am experiencing weird behavior when executing the following line of code:

using (GetObjectResponse response = await client.GetObjectAsync(request).ConfigureAwait(false))

This happens on all of my pages where I use the S3 code. Once the xaml page is displayed, the subsequent lines are processed. I don't want the page to appear as there is more code to be processed. Here's an extract of the code I'm using:

 using var client = new AmazonS3Client("test", "test", Amazon.RegionEndpoint.USEast1);
var bucketName = "mybucket";
var keyName = "myfile.txt";

GetObjectRequest request = new GetObjectRequest
    BucketName = bucketName,
    Key = keyName,

using (GetObjectResponse response = await client.GetObjectAsync(request).ConfigureAwait(false))
    using (Stream responseStream = response.ResponseStream)
    using (StreamReader reader = new StreamReader(responseStream))
        string inputString;
        string line = "";
        while ((inputString = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
            string[] parts = inputString.Split('#');

Not sure what is causing this issue so any help would be welcome.


A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,851 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,214 questions
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
762 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,146 Reputation points Microsoft Vendor


    Once the xaml page is displayed, the subsequent lines are processed.

    The subsequent lines (using (GetObjectResponse response = await client.GetObjectAsync(request).ConfigureAwait(false))) are put in GetCount method in your ViewModel(HomeViewModel) class, and you call this method in the constructor of HomeViewModel, which means that this method is called when you create a HomeViewModel object, and the HomeViewModel object isn't created until this method has run.

    I don't want the page to appear as there is more code to be processed.

    You could call the method in Page.OnAppearing method (or Page.Loaded Event) instead of the constructor of ViewModel.

    For example:


    protected override async void OnAppearing()
         HomeViewModel homeViewModel = this.BindingContext as HomeViewModel;
         await homeViewModel.GetCount();

    ViewMode l(I've omitted some methods)

    public class HomeViewModel :...
         public HomeViewModel()
            // _ = GetCount();
        public async Task GetCount()

    Best Regards,

    Wenyan Zhang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments