{"record":{"id":"45d4505a9959966f","repo":"dotnet/wpf","slug":"could-not-load-data-file","errorCode":null,"errorMessage":"Could not load data file.","messagePattern":"Could not load data file\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/main/ResourceGenerator.cs","lineNumber":221,"sourceCode":"        {\n            Usage();\n            throw new ApplicationException(message);\n        }\n\n\n        //+-----------------------------------------------------------------------------\n        //\n        //  Function:  LoadDocument\n        //\n        //------------------------------------------------------------------------------\n\n        private static XmlDocument LoadDocument(string xmlFile, string schemaFile)\n        {\n            XmlDocument document = XmlLoader.Load(xmlFile, schemaFile);\n\n            if (document == null)\n            {\n                throw new ApplicationException(String.Format(\"Could not load data file.\"));\n            }\n\n            return document;\n        }\n\n\n        //+-----------------------------------------------------------------------------\n        //\n        //  Function:  DisplayLogo\n        //\n        //------------------------------------------------------------------------------\n\n        private static void DisplayLogo()\n        {\n            Console.WriteLine();\n            Console.WriteLine(\"Avalon MilCodeGen source-code generator.\");\n            Console.WriteLine();\n        }","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/main/ResourceGenerator.cs#L203-L239","documentation":"LoadDocument in ResourceGenerator calls XmlLoader.Load(xmlFile, schemaFile) and throws ApplicationException('Could not load data file.') when the loader returns null. A null result means the XML document could not be loaded/validated against the XSD schema (the loader swallows the underlying failure and reports it by returning null).","triggerScenarios":"XmlLoader.Load returning null because the XML is malformed, fails XSD schema validation, or cannot be read, after both input files passed the existence check in ProcessArgs.","commonSituations":"Hand-edited XML with a syntax error; XML that does not conform to the schema (missing required elements/attributes, wrong element order); encoding problems; a schema/XML version mismatch after edits.","solutions":["Validate the XML against the XSD manually (e.g. with xmllint --schema or Visual Studio) to see the concrete validation error.","Fix XML well-formedness errors (unclosed tags, invalid characters, wrong encoding declaration).","Update the XML to conform to the current schema, or use the matching schema version.","Check that the file is readable and not empty/locked by another process."],"exampleFix":"// validate before invoking the generator\nxmllint --noout --schema schema.xsd model.xml\n// fix reported validation errors, then\ncsp ResourceGenerator model.xml schema.xsd","handlingStrategy":"validation","validationCode":"// validate XML against the XSD before invoking the generator\nusing var reader = XmlReader.Create(xmlPath);\nvar doc = new XmlDocument();\ndoc.Load(reader); // throws with the concrete parse error\nvar schemas = new XmlSchemaSet();\nschemas.Add(null, schemaPath);\ndoc.Schemas = schemas;\ndoc.Validate(null); // throws with the concrete validation error","typeGuard":null,"tryCatchPattern":"try { generator.LoadDocument(xmlFile, schemaFile); }\ncatch (ApplicationException ex) when (ex.Message.Contains(\"Could not load data file\")) { /* run xmllint --schema to get the real underlying error */ }","preventionTips":["Validate the XML against the XSD before each generator run.","Avoid hand-editing generated XML without re-validating.","Keep the XML and XSD versions in sync."],"tags":["xml","schema-validation","codegen","load-failure"],"backgroundTag":"xml-parse-error","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}