dotnet/wpf · error · FileNotFoundException

Schema not found

Error message

Schema not found

What it means

ResourceGenerator.ProcessArgs throws FileNotFoundException when the XSD schema file supplied via parsedArgs.xsdFile does not exist. The XSD is required to validate the XML data file during loading, so the tool fails fast before LoadDocument runs.

Solutions

  1. Verify the XSD path exists at the exact location the tool resolves it.
  2. Deploy/copy the schema next to the XML input and reference it explicitly with an absolute path.
  3. Fix the schema argument in the invoking script or build target.

Example fix

// before
csp ResourceGenerator model.xml oldschema.xsd
// after
csp ResourceGenerator model.xml C:\tools\mcg\schema.xsd
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(xsdPath))
    throw new FileNotFoundException($"Schema file missing: {Path.GetFullPath(xsdPath)}");

Try / catch

try { generator.ProcessArgs(args); }
catch (FileNotFoundException ex) when (ex.FileName == xsdPath) { Console.Error.WriteLine($"Schema not found: {ex.FileName}"); return 2; }

Prevention

When it happens

Trigger: Running ResourceGenerator with an xsdFile path that does not exist: wrong schema name, schema not deployed alongside the tool, relative path broken by a different working directory.

Common situations: Copying the generator to a machine without the accompanying schema; build scripts that copy the XML but forget the XSD; renaming the schema during a tooling upgrade.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/main/ResourceGenerator.cs:191

            {
                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();
            throw new ApplicationException(message);
        }


        //+-----------------------------------------------------------------------------

View on GitHub (pinned to 81131a70a4)