{"record":{"id":"f605629870fca0a7","repo":"memstechtips/Winhance","slug":"destination-path-cannot-be-empty","errorCode":null,"errorMessage":"Destination path cannot be empty.","messagePattern":"Destination path cannot be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Winhance.Infrastructure/Features/AdvancedTools/Services/WimCustomizationService.cs","lineNumber":196,"sourceCode":"            await _fileSystemService.WriteAllTextAsync(destPath, xmlContent).ConfigureAwait(false);\r\n\r\n            _logService.LogInformation($\"Added autounattend.xml to image: {destPath}\");\r\n            return true;\r\n        }\r\n        catch (Exception ex)\r\n        {\r\n            _logService.LogError($\"Error adding XML to image: {ex.Message}\", ex);\r\n            return false;\r\n        }\r\n    }\r\n\r\n    public async Task<string> DownloadUnattendedWinstallXmlAsync(\r\n        string destinationPath,\r\n        IProgress<TaskProgressDetail>? progress = null,\r\n        CancellationToken cancellationToken = default)\r\n    {\r\n        if (string.IsNullOrEmpty(destinationPath))\r\n            throw new ArgumentException(\"Destination path cannot be empty.\", nameof(destinationPath));\r\n\r\n        var destinationDir = _fileSystemService.GetDirectoryName(destinationPath);\r\n        if (string.IsNullOrEmpty(destinationDir))\r\n            throw new ArgumentException(\"Destination path must include a directory.\", nameof(destinationPath));\r\n\r\n        try\r\n        {\r\n            progress?.Report(new TaskProgressDetail\r\n            {\r\n                StatusText = _localization.GetString(\"Progress_DownloadingXml\"),\r\n                TerminalOutput = UnattendedWinstallXmlUrl\r\n            });\r\n\r\n            var xmlContent = await _httpClient.GetStringAsync(UnattendedWinstallXmlUrl, cancellationToken).ConfigureAwait(false);\r\n\r\n            _fileSystemService.CreateDirectory(destinationDir);\r\n            await _fileSystemService.WriteAllTextAsync(destinationPath, xmlContent, cancellationToken).ConfigureAwait(false);\r\n\r","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/memstechtips/Winhance/blob/f23d554eb2d6400b1827bcc46b91294ffa53fbc9/src/Winhance.Infrastructure/Features/AdvancedTools/Services/WimCustomizationService.cs#L178-L214","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nif (string.IsNullOrEmpty(destinationPath))\n    throw new ArgumentException(\"Destination path cannot be empty.\", nameof(destinationPath));\n\n// after: trim-aware check with a clearer message at the call boundary\nif (string.IsNullOrWhiteSpace(destinationPath))\n    throw new ArgumentException(\"A destination file path is required to save the unattended-install XML.\", nameof(destinationPath));","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(destinationPath))\n    return; // or show a UI validation error before calling the API","typeGuard":null,"tryCatchPattern":"catch (ArgumentException ex) when (ex.ParamName == nameof(destinationPath))\n{\n    // Show the user a validation error: a destination file path is required.\n}","preventionTips":["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."],"tags":["argument-validation","filesystem","download","contract"],"backgroundTag":null,"analyzedSha":"f23d554eb2d6400b1827bcc46b91294ffa53fbc9","analyzedAt":"2026-08-13T17:55:20.922Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}