A component of ASP.NET Core for creating RESTful web services that support HTTP-based communication between clients and servers.
Hi @Scott Huang ,
From the screenshot, the issue is that DownloadAndShareFileAsync(...) is being called inside CreateMauiApp().
CreateMauiApp() is intended only for configuring and building the MAUI app. It must return MauiApp synchronously, so it is not a suitable place to run an async download/share operation.
If DownloadAndShareFileAsync returns Task, then calling it there will either:
- produce a compile/build problem if the async flow is handled incorrectly, or
- run as fire-and-forget at startup, which is not recommended for this scenario.
I would suggest moving this call out of MauiProgram.cs and invoking it from UI logic instead, such as a button click handler, command, or page lifecycle method.
For example:
private async void OnDownloadClicked(object sender, EventArgs e)
{
await MauiProgram.DownloadAndShareFileAsync("https://...", "Myfile.txt");
}
And keep CreateMauiApp() focused on app startup only:
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
// register services, fonts, toolkit, etc.
return builder.Build();
}
Please also double-check the method call syntax in the screenshot. It looks like there may be a missing comma between the URL and file name arguments.
Note: the code snippets above are for reference only, to show the recommended pattern. They may need to be adjusted to match your page, event handler name, and current project structure rather than copied directly as-is.
Hope this helps! If my answer was helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.