memstechtips/Winhance · error · ArgumentException
Destination path cannot be empty.
Error message
Destination path cannot be empty.
What it means
ArgumentException thrown by DownloadUnattendedWinstallXmlAsync when destinationPath is null or empty. This is an input-contract violation on the caller side — the method cannot decide where to write the downloaded autounattend.xml, so it refuses immediately rather than writing to an unspecified location.
Source
Thrown at src/Winhance.Infrastructure/Features/AdvancedTools/Services/WimCustomizationService.cs:196
await _fileSystemService.WriteAllTextAsync(destPath, xmlContent).ConfigureAwait(false);
_logService.LogInformation($"Added autounattend.xml to image: {destPath}");
return true;
}
catch (Exception ex)
{
_logService.LogError($"Error adding XML to image: {ex.Message}", ex);
return false;
}
}
public async Task<string> DownloadUnattendedWinstallXmlAsync(
string destinationPath,
IProgress<TaskProgressDetail>? progress = null,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(destinationPath))
throw new ArgumentException("Destination path cannot be empty.", nameof(destinationPath));
var destinationDir = _fileSystemService.GetDirectoryName(destinationPath);
if (string.IsNullOrEmpty(destinationDir))
throw new ArgumentException("Destination path must include a directory.", nameof(destinationPath));
try
{
progress?.Report(new TaskProgressDetail
{
StatusText = _localization.GetString("Progress_DownloadingXml"),
TerminalOutput = UnattendedWinstallXmlUrl
});
var xmlContent = await _httpClient.GetStringAsync(UnattendedWinstallXmlUrl, cancellationToken).ConfigureAwait(false);
_fileSystemService.CreateDirectory(destinationDir);
await _fileSystemService.WriteAllTextAsync(destinationPath, xmlContent, cancellationToken).ConfigureAwait(false);
View on GitHub (pinned to f23d554eb2)
Solutions
- Validate the destination path is non-empty in the UI/viewmodel before invoking the download, and disable the action otherwise.
- Pass a sensible default destination (e.g. inside the working directory) when the caller has none.
- Guard at the call site with `if (string.IsNullOrWhiteSpace(path)) return;` so the contract violation never reaches the API.
- Use argument-null checking (`destinationPath ?? throw ...`) consistently across the API surface.
Example fix
// before
if (string.IsNullOrEmpty(destinationPath))
throw new ArgumentException("Destination path cannot be empty.", nameof(destinationPath));
// after: trim-aware check with a clearer message at the call boundary
if (string.IsNullOrWhiteSpace(destinationPath))
throw new ArgumentException("A destination file path is required to save the unattended-install XML.", nameof(destinationPath)); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(destinationPath))
return; // or show a UI validation error before calling the API Try / catch
catch (ArgumentException ex) when (ex.ParamName == nameof(destinationPath))
{
// Show the user a validation error: a destination file path is required.
} Prevention
- Validate the path is non-empty in the viewmodel before enabling the download action.
- Default to a known-good destination directory when the user supplies none.
- Use a SaveFileDialog that forces a full path.
When it happens
Trigger: A caller invokes DownloadUnattendedWinstallXmlAsync(null, ...) or DownloadUnattendedWinstallXmlAsync("", ...). The parameter is bound from a UI text box that was left blank, from a deserialized settings object whose property defaulted to null, or from a path-builder that returned empty on a bad input.
Common situations: The destination path textbox in the UI was not validated before the download button was enabled. A settings/config object was deserialized without the destination property. A path-combine produced an empty string because one input component was null.
Related errors
- Destination path must include a directory.
- Could not delete the existing working directory '{workingDir
- Boot file not found: {etfsbootPath}
- UEFI boot file not found: {efisysPath}
- Insufficient disk space on {driveName} for {operationName}.
AI-assisted analysis of memstechtips/Winhance@f23d554eb2 (2026-08-13).
Data as JSON: /api/errors/f605629870fca0a7.
Report an issue: GitHub.