CommunityToolkit / CommunityToolkit/Maui

[BUG] File saver not opening when application is run as Administrator and WindowsPackageType None

Open
#2,579 2 comments 0 reactions 0 assignees View on GitHub
bug unverified
Dominant language
C#
Stars
2.7k
Forks
500
Avg merge
2d 14h
Merged PRs (30d)
7

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Did you read the "Reporting a bug" section on Contributing file?

- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

### Current Behavior

Found with version 9.1.1 of the Toolkit.

I have a MAUI Blazor Hybrid application with WindowsPackageType None where I call the FileSaver.Default.SaveAsync. This correctly opens a save dialog when running the application not as administrator.
If I run the application as administrator nothing happens. I do see however that the FileSaverResult contains an Exception with no error message and a small stack trace.
` at CommunityToolkit.Maui.Storage.FileSaverImplementation.d__6.MoveNext()
at CommunityToolkit.Maui.Storage.FileSaverImplementation.d__6.MoveNext()
at CommunityToolkit.Maui.Storage.FileSaverImplementation.d__0.MoveNext()`

This is the code I am using:
` using (var stream = new MemoryStream(Encoding.Default.GetBytes(content)))
{
var fileSaverResult = await FileSaver.Default.SaveAsync(AppDomain.CurrentDomain.BaseDirectory, fileName, stream, new CancellationToken());

if (fileSaverResult.Exception != null)
throw fileSaverResult.Exception;

// save dialog cancelled
if (string.IsNullOrEmpty(fileSaverResult.FilePath))
return;

await MainPage.DisplayAlert("Success", $"File saved at {fileSaverResult.FilePath}", "OK");
} `

### Expected Behavior

A file save dialog is opened just as running the application normally without being an administrator.

### Steps To Reproduce

1. Make sure VS is started as Administator or run the generated .exe as administator.
2. Create a new MAUI Blazor Hybrid project.
3. Setup the community toolkit.
4. Set the WindowsPackageType type to None
5. Set the commandName to Project in launchsettings.json
6. Create a button that triggers the dialog.
7. Observe that the file dialog is not opened.

### Link to public reproduction project repository

https://github.com/axestos/ReproductionFileSaverIssue

### Environment

```markdown
- .NET MAUI CommunityToolkit: 9.1.1
- OS: Windows 11
- .NET MAUI: 8.0.1
```

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with FileSaverImplementation.InternalSaveAsync, using the reported stack trace and the reproduction project as entry points. Reproduce the issue with WindowsPackageType set to None, commandName set to Project in launchsettings.json, and the application run as administrator. Done means FileSaver.Default.SaveAsync opens the expected save dialog in that configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.