dotnet/wpf · error · FileNotFoundException

XML file not found

Error message

XML file not found

What it means

SimpleGenerator.ProcessArgs validates its inputs and throws FileNotFoundException when the XML data file supplied via parsedArgs.xmlFile does not exist. As with ResourceGenerator, this is a fail-fast existence check performed before the resource model is loaded.

Solutions

  1. Verify the exact XML path exists from the tool's working directory.
  2. Pass an absolute path in the invoking script.
  3. Restore or check out the missing XML file before running the generator.

Example fix

// before
csp SimpleGenerator data.xml
// after
csp SimpleGenerator C:\src\gen\data.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

When it happens

Trigger: Running the SimpleGenerator tool with an XML path that does not exist: typo, wrong working directory, relative path resolved differently than expected, or the file was removed before the run.

Common situations: Build/automation scripts invoking the generator from a different cwd; missing file in CI checkout; renaming or moving the XML data file without updating the invocation.

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/b03efe403df1e9be. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/main/SimpleGenerator.cs:185

            //
            // Handle "-h" option.
            //

            if (parsedArgs.help)
            {
                Usage();
                data = null;
                return;
            }


            //
            // Check that files exist
            //

            if (!File.Exists(parsedArgs.xmlFile))
            {
                throw new FileNotFoundException("XML file not found", parsedArgs.xmlFile);
            }

            //
            // Load the XML file and create the resource model from it
            //

            // Create an instance of the XmlSerializer specifying type and namespace.
            XmlSerializer serializer = new XmlSerializer(Type.GetType(parsedArgs.dataType));

            // A FileStream is needed to read the XML document.
            using (FileStream fs = new FileStream(parsedArgs.xmlFile, FileMode.Open, FileAccess.Read))
            using (XmlReader reader = new XmlTextReader(fs))
            {
                data = (CG) serializer.Deserialize(reader);
            }

            data.OutputDirectory = parsedArgs.outputDirectory;
        }

View on GitHub (pinned to 81131a70a4)