dotnet/wpf · error · FileNotFoundException
XML file not found
Error message
XML file not found
What it means
ResourceGenerator.ProcessArgs validates its command-line inputs after parsing and throws FileNotFoundException when the XML data file supplied via parsedArgs.xmlFile does not exist on disk. This is a fail-fast check so the generator stops before attempting to load a missing resource model.
Solutions
- Verify the path passed for the XML file exists: run File.Exists / ls on the exact path.
- Use an absolute path in the build script to avoid working-directory surprises.
- Fix the argument in the invoking script/target, or check out/restore the missing XML file.
- Check case sensitivity of the file name on Linux-style filesystems.
Example fix
// before csp ResourceGenerator model.xml // (model.xml not in current dir) // after csp ResourceGenerator $(MSBuildProjectDirectory)\Resources\model.xml
Defensive patterns
Strategy: validation
Validate before calling
if (!File.Exists(xmlPath))
throw new FileNotFoundException($"XML data file missing: {Path.GetFullPath(xmlPath)}"); Try / catch
try { generator.ProcessArgs(args); }
catch (FileNotFoundException ex) when (ex.FileName == xmlPath) { Console.Error.WriteLine($"XML file not found: {ex.FileName}"); return 2; } Prevention
- Use absolute paths in build scripts and CI.
- Check File.Exists on all inputs before invoking the generator.
- Ensure the XML data file is committed/generated before the tool runs.
When it happens
Trigger: Running the ResourceGenerator tool with a path to the XML file that does not exist: misspelled file name, wrong working directory, relative path resolved from an unexpected location, or the file was deleted/moved before the run.
Common situations: Build scripts or MSBuild targets invoking the tool from a different working directory than expected; CI checkouts missing generated or checked-in XML data files; typos in the XML path argument.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/3124ccea6a8724fe.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/main/ResourceGenerator.cs:186
//
// Handle "-h" option.
//
if (parsedArgs.help)
{
Usage();
resourceModel = null;
return;
}
//
// Check that files exist
//
if (!File.Exists(parsedArgs.xmlFile))
{
throw new FileNotFoundException("XML file not found", parsedArgs.xmlFile);
}
if (!File.Exists(parsedArgs.xsdFile))
{
throw new FileNotFoundException("Schema not found", parsedArgs.xsdFile);
}
//
// Load the XML file and create the resource model from it
//
XmlDocument document = LoadDocument(parsedArgs.xmlFile, parsedArgs.xsdFile);
resourceModel = new ResourceModel(document, parsedArgs.outputDirectory);
}
public static void ReportArgumentError(string message)
{
Usage();View on GitHub (pinned to 81131a70a4)