{"record":{"id":"268753586437098e","repo":"stride3d/stride","slug":"compilationcontext-should-inherit-from-icompilationcontext-268753","errorCode":null,"errorMessage":"compilationContext should inherit from ICompilationContext","messagePattern":"compilationContext should inherit from ICompilationContext","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Compiler/AssetDependenciesCompiler.cs","lineNumber":26,"sourceCode":"\nnamespace Stride.Core.Assets.Compiler;\n\n/// <summary>\n/// An asset compiler that will compile an asset with all its dependencies.\n/// </summary>\npublic class AssetDependenciesCompiler\n{\n    public readonly BuildDependencyManager BuildDependencyManager;\n\n    /// <summary>\n    /// Raised when a single asset has been compiled.\n    /// </summary>\n    public event EventHandler<AssetCompiledArgs>? AssetCompiled;\n\n    public AssetDependenciesCompiler(Type compilationContext)\n    {\n        if (!typeof(ICompilationContext).IsAssignableFrom(compilationContext))\n            throw new InvalidOperationException($\"{nameof(compilationContext)} should inherit from ICompilationContext\");\n\n        BuildDependencyManager = new BuildDependencyManager();\n    }\n\n    /// <summary>\n    /// Prepare the list of assets to be built, building all the steps and linking them properly\n    /// </summary>\n    /// <param name=\"context\">The AssetCompilerContext</param>\n    /// <param name=\"assetItems\">The assets to prepare for build</param>\n    /// <returns></returns>\n    public AssetCompilerResult PrepareMany(AssetCompilerContext context, List<AssetItem> assetItems)\n    {\n        var finalResult = new AssetCompilerResult();\n        var compiledItems = new Dictionary<AssetId, BuildStep>();\n        foreach (var assetItem in assetItems)\n        {\n            var visitedItems = new HashSet<BuildAssetNode>();\n            Prepare(finalResult, context, assetItem, context.CompilationContext, visitedItems, compiledItems);","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Compiler/AssetDependenciesCompiler.cs#L8-L44","documentation":"The AssetDependenciesCompiler constructor takes the Type of the compilation context to use and validates that it implements ICompilationContext, throwing InvalidOperationException otherwise. Note the check message says \"should inherit from\" but the actual condition is assignability to the ICompilationContext interface.","triggerScenarios":"Constructing new AssetDependenciesCompiler(typeof(SomeCompilerBase)) with a type that does not implement ICompilationContext — e.g. passing an AssetCompiler, an Asset type, or an abstract context base class that only indirectly relates to compilation contexts.","commonSituations":"Mixing up AssetCompilerRegistry's compiler type with the compilation context type when wiring the dependency compiler; renaming/refactoring context classes so the referenced type no longer implements ICompilationContext; reflection-resolved type string pointing at the wrong class.","solutions":["Pass a concrete type implementing ICompilationContext, e.g. typeof(AssetCompilerContext).","Swap the argument if you accidentally passed the compiler type instead of the context type.","Verify with typeof(ICompilationContext).IsAssignableFrom(candidateType) before constructing.","Update the type reference if the context class was refactored/renamed and lost its interface."],"exampleFix":"// before\nvar depsCompiler = new AssetDependenciesCompiler(typeof(MyAssetCompiler)); // compiler, not a context\n// after\nvar depsCompiler = new AssetDependenciesCompiler(typeof(MyAssetCompilerContext)); // implements ICompilationContext","handlingStrategy":"validation","validationCode":"if (!typeof(ICompilationContext).IsAssignableFrom(contextType))\n    throw new ArgumentException(\"Type must implement ICompilationContext\", nameof(contextType));\nvar deps = new AssetDependenciesCompiler(contextType);","typeGuard":"static bool IsCompilationContext(Type t) => t != null && typeof(ICompilationContext).IsAssignableFrom(t);","tryCatchPattern":"try\n{\n    var deps = new AssetDependenciesCompiler(contextType);\n}\ncatch (InvalidOperationException ex)\n{\n    logger.Error($\"{contextType} is not an ICompilationContext: {ex.Message}\");\n}","preventionTips":["Pass typeof(YourContext) where YourContext : ICompilationContext, not the compiler type.","Add a startup smoke test that constructs AssetDependenciesCompiler with your context type.","Keep context classes implementing ICompilationContext after refactors."],"tags":["type-mismatch","asset-compilation","constructor","interface"],"backgroundTag":"type-mismatch","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"}