{"record":{"id":"bd818f43b98df61d","repo":"stride3d/stride","slug":"could-not-read-file-content-for-arg2-path","errorCode":null,"errorMessage":"Could not read file content for {arg2.Path}","messagePattern":"Could not read file content for (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Generators/EffectGenerator.cs","lineNumber":29,"sourceCode":"{\n    public void Initialize(IncrementalGeneratorInitializationContext context)\n    {\n        var shaderFiles =\n            context\n                .AdditionalTextsProvider\n                .Where(x => Path.GetExtension(x.Path).ToLowerInvariant() is \".sdfx\" or \".sdsl\");\n\n        context.RegisterSourceOutput(shaderFiles, GenerateShaderKeysAndEffects);\n    }\n\n    private void GenerateShaderKeysAndEffects(SourceProductionContext arg1, AdditionalText arg2)\n    {\n        var filename = GetSafeHintName(arg2.Path);\n        var isSdfx = Path.GetExtension(arg2.Path).Equals(\".sdfx\", StringComparison.OrdinalIgnoreCase);\n\n        try\n        {\n            var preprocessedText = MonoGamePreProcessor.Run(arg2.GetText()?.ToString() ?? throw new InvalidOperationException($\"Could not read file content for {arg2.Path}\"), arg2.Path);\n            var parsed = SDSLParser.Parse(preprocessedText);\n            if (parsed.Errors.Count > 0)\n            {\n                var sb = new StringBuilder();\n                foreach (var error in parsed.Errors)\n                    sb.AppendLine($\"#error Parse error: {error}\");\n                arg1.AddSource(filename, sb.ToString());\n                return;\n            }\n            else if (parsed.AST == null)\n            {\n                arg1.AddSource(filename, \"#error No AST parsed\");\n                return;\n            }\n\n            // .sdfx files must declare 'effect', not 'shader' — catch the mistake here\n            // instead of silently emitting unbuildable C#.\n            if (isSdfx && parsed.AST is Parsing.ShaderFile sdfxFile && HasShaderClassDeclaration(sdfxFile))","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Generators/EffectGenerator.cs#L11-L47","documentation":"EffectGenerator.GenerateShaderKeysAndEffects throws InvalidOperationException when arg2.GetText() returns null, i.e. the shader source file (.sdfx) content could not be read. The generator needs the preprocessed text to parse and emit shader keys/effects.","triggerScenarios":"Running the Stride shader effect generator over a .sdfx file whose text cannot be obtained — unreadable/corrupt file, wrong path, encoding issues.","commonSituations":"Broken build pipeline where the shader source wasn't copied/generated; path casing or mapping issues on case-sensitive file systems; file deleted or locked between enumeration and read.","solutions":["Verify the .sdfx file exists and is readable at arg2.Path (check project include/copy settings).","Re-run the Stride shader compiler/generator with a clean output to restore missing intermediates.","Check file encoding — save the file as UTF-8 and re-add to the project.","Confirm the file is properly included in the stride project so its content is embedded/accessible."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (!File.Exists(arg2.Path) || new FileInfo(arg2.Path).Length == 0)\n    throw new FileNotFoundException($\"Shader source missing or empty: {arg2.Path}\");","typeGuard":null,"tryCatchPattern":"try { GenerateShaderKeysAndEffects(arg1, arg2); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Could not read file content\")) { log.LogError($\"Unreadable shader source: {arg2.Path}\"); throw; }","preventionTips":["Ensure .sdfx files are included in the project and copied to build output","Save shader files as UTF-8 without exotic encodings","Use clean/rebuild to restore missing sources"],"tags":["csharp","file-read","shaders"],"backgroundTag":"file-read-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}