{"record":{"id":"33438742955a3512","repo":"abpframework/abp","slug":"invalid-include-file-format-in-source-physicalpa","errorCode":null,"errorMessage":"Invalid include file format in {_source.PhysicalPath}. Usage example: <%$ include: ErrorPage.js %>","messagePattern":"Invalid include file format in (.+?)\\. Usage example: <%\\$ include: ErrorPage\\.js %>","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateRazorPage.cs","lineNumber":209,"sourceCode":"        private string ProcessFileIncludes()\n        {\n            var basePath = Path.GetDirectoryName(_source.PhysicalPath);\n            var cshtmlContent = File.ReadAllText(_source.PhysicalPath);\n\n            var startMatch = \"<%$ include: \";\n            var endMatch = \" %>\";\n            var startIndex = 0;\n            while (startIndex < cshtmlContent.Length)\n            {\n                startIndex = cshtmlContent.IndexOf(startMatch, startIndex, StringComparison.Ordinal);\n                if (startIndex == -1)\n                {\n                    break;\n                }\n                var endIndex = cshtmlContent.IndexOf(endMatch, startIndex, StringComparison.Ordinal);\n                if (endIndex == -1)\n                {\n                    throw new InvalidOperationException($\"Invalid include file format in {_source.PhysicalPath}. Usage example: <%$ include: ErrorPage.js %>\");\n                }\n                var includeFileName = cshtmlContent.Substring(startIndex + startMatch.Length, endIndex - (startIndex + startMatch.Length));\n                _logger.LogInformation(\"    Inlining file {0}\", includeFileName);\n                var includeFileContent = File.ReadAllText(Path.Combine(basePath, includeFileName));\n                cshtmlContent = string.Concat(cshtmlContent.Substring(0, startIndex), includeFileContent, cshtmlContent.Substring(endIndex + endMatch.Length));\n                startIndex += includeFileContent.Length;\n            }\n            return cshtmlContent;\n        }\n    }\n\n    private class RazorPageGeneratorResult\n    {\n        public string FilePath { get; set; }\n\n        public string GeneratedCode { get; set; }\n    }\n}","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateRazorPage.cs#L191-L227","documentation":"Thrown by GenerateRazorPage during cshtml template processing when an include directive opens with '<%$ include:' but no matching closing ' %>' delimiter is found. The code scans for include directives to inline referenced files (like ErrorPage.js) into the generated .cshtml content; if the start marker is found but IndexOf for the end marker returns -1, the directive is malformed and cannot be resolved.","triggerScenarios":"A .cshtml template file contains '<%$ include: SomeFile.js' without the closing ' %>', or the closing delimiter was accidentally removed during editing. The while-loop finds startIndex != -1 but endIndex == -1.","commonSituations":"Template customization where an include directive was partially edited, copy-paste errors leaving unclosed directives, or automated tooling that mangled template files. Occurs during `abp generate-razor-page` or similar template generation commands.","solutions":["Open the template file referenced by _source.PhysicalPath and fix the include directive to use the full format: `<%$ include: FileName.js %>`","Verify all include directives have matching start (`<%$ include:`) and end (` %>`) delimiters","If you do not need the include, remove the entire directive rather than leaving it partially open"],"exampleFix":"<!-- before -->\n<%$ include: ErrorPage.js\n\n<!-- after -->\n<%$ include: ErrorPage.js %>","handlingStrategy":"validation","validationCode":"// Check that all include directives in the template are well-formed before processing\nvar content = File.ReadAllText(templatePath);\nvar startMatches = Regex.Matches(content, @\"<%\\$ include:\");\nforeach (Match start in startMatches)\n{\n    var endIndex = content.IndexOf(\" %>\", start.Index, StringComparison.Ordinal);\n    if (endIndex == -1)\n    {\n        Console.Error.WriteLine($\"Malformed include directive at position {start.Index} in {templatePath}\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var result = generator.Generate();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Invalid include file format\"))\n{\n    logger.LogError(\"Template has an unclosed include directive. Fix the <%$ include: ... %> syntax.\");\n}","preventionTips":["Always close include directives with ' %>' immediately after authoring them","Lint template files for balanced delimiters before running generation","Use a consistent template authoring convention: '<%$ include: FileName.ext %>'"],"tags":["cli","abp-cli","template","razor","syntax-error"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}