{"record":{"id":"13aace2e3a79e65e","repo":"stride3d/stride","slug":"symbol-symbol-has-not-been-imported-or-created-properly","errorCode":null,"errorMessage":"Symbol {symbol} has not been imported or created properly","messagePattern":"Symbol (.+?) has not been imported or created properly","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Literals.cs","lineNumber":371,"sourceCode":"            if (value.Type is not PointerType && value.Type != itemType)\n                value.ProcessSymbol(table, itemType);\n        }\n    }\n\n    public override string ToString()\n        => $\"{Values.Count}({string.Join(\", \", Values.Select(x => x.ToString()))})\";\n}\n\npublic abstract partial class IdentifierBase(string name, TextLocation info) : Literal(info)\n{\n    public string Name { get; set; } = name;\n\n    public Symbol? ResolvedSymbol { get; set; }\n\n    public static SpirvValue EmitSymbol(SpirvBuilder builder, SpirvContext context, Symbol symbol, bool constantOnly, int? instance = null)\n    {\n        if (symbol.IdRef == 0)\n            throw new InvalidOperationException($\"Symbol {symbol} has not been imported or created properly\");\n\n        var resultType = context.GetOrRegister(symbol.Type);\n        var result = new SpirvValue(symbol.IdRef, resultType, symbol.Id.Name);\n\n        // Shader symbols are treated separately (we want to return only the shader instance (or this if not specified))\n        if (symbol.Id.Kind == SymbolKind.Shader)\n        {\n            if (constantOnly)\n                throw new NotImplementedException();\n\n            if (instance == null)\n                instance = builder.Insert(new OpThisSDSL(context.Bound++)).ResultId;\n            result.Id = instance.Value;\n            return result;\n        }\n\n        if (symbol.ExternalConstant is { } externalConstant)\n        {","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Literals.cs#L353-L389","documentation":"Thrown by EmitSymbol when a symbol's IdRef (its SPIR-V result id) is 0, meaning the symbol was never imported into SPIR-V or created by an earlier compilation pass. The emitter cannot reference a symbol that has no SPIR-V id assigned.","triggerScenarios":"Calling EmitSymbol (directly or via CompileSymbol) on a Symbol whose IdRef was never populated by ShaderDefinition.ImportSymbol or the symbol-creation passes, e.g. when a pass that assigns IdRefs was skipped or failed silently.","commonSituations":"Shaders referencing extern/global variables that failed to import; compilation order issues where a symbol is emitted before its defining shader is imported; symbols created in one CompilerUnit but emitted in another.","solutions":["Ensure ImportSymbol (or equivalent creation pass) runs for the symbol before EmitSymbol is called","Check earlier compilation errors — a failed import often leaves IdRef at 0; fix the root cause first","Verify symbols are emitted in the correct pass order (types/globals before use sites)"],"exampleFix":"// before\nCompileSymbol(table, builder, context, constantOnly); // ResolvedSymbol never imported\n// after\nvar imported = ShaderDefinition.ImportSymbol(table, context, resolvedSymbol); // assigns IdRef\nCompileSymbol(table, builder, context, constantOnly);","handlingStrategy":"validation","validationCode":"if (symbol.IdRef == 0)\n    throw new InvalidOperationException($\"Symbol {symbol.Id.Name} was never imported (IdRef=0)\");","typeGuard":"bool IsEmittable(Symbol s) => s.IdRef != 0;","tryCatchPattern":"try { EmitSymbol(builder, context, symbol, constantOnly); }\ncatch (InvalidOperationException ex) { log.Error($\"Symbol import missing: {ex.Message}\"); throw; }","preventionTips":["Always run ImportSymbol before emission","Fail fast on earlier import errors instead of continuing","Assert IdRef != 0 in debug builds"],"tags":["spirv","symbols","shader-compilation"],"backgroundTag":"internal-invariant-violation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}