{"record":{"id":"cadf7b7234ced3ed","repo":"abpframework/abp","slug":"public-class-declaration-not-found","errorCode":null,"errorMessage":"\"public class\" declaration not found!","messagePattern":"\"public class\" declaration not found!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ModuleClassDependcyAdder.cs","lineNumber":47,"sourceCode":"\n        File.WriteAllText(path, file);\n    }\n\n    protected virtual string InsertDependsOnAttribute(string file, string moduleName)\n    {\n        var indexOfPublicClassDeclaration = GetIndexOfWhereDependsOnWillBeAdded(file);\n        var dependsOnAttribute = GetDependsOnAttribute(moduleName);\n\n        return file.Insert(indexOfPublicClassDeclaration, dependsOnAttribute);\n    }\n\n    protected virtual int GetIndexOfWhereDependsOnWillBeAdded(string file)\n    {\n        var indexOfPublicClassDeclaration = file.IndexOf(\"public class\", StringComparison.Ordinal);\n\n        if (indexOfPublicClassDeclaration < 0)\n        {\n            throw new Exception(\"\\\"public class\\\" declaration not found!\");\n        }\n\n        return indexOfPublicClassDeclaration;\n    }\n\n    protected virtual string GetDependsOnAttribute(string moduleName)\n    {\n        return \"[DependsOn(typeof(\" + moduleName + \"))]\" + Environment.NewLine + \"    \";\n    }\n\n    protected virtual void ParseModuleNameAndNameSpace(string module, out string nameSpace, out string moduleName)\n    {\n        var words = module?.Split('.');\n\n        if (words == null || words.Length <= 1)\n        {\n            nameSpace = null;\n            moduleName = module;","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ModuleClassDependcyAdder.cs#L29-L65","documentation":"ModuleClassDependcyAdder.GetIndexOfWhereDependsOnWillBeAdded searches the module file text for the literal 'public class' and throws if IndexOf returns -1. Adding a [DependsOn] attribute requires inserting it immediately before the module class declaration; if the class is declared differently (static, internal, partial-first-line, file-scoped namespace reformatted, or file is empty/corrupt), the insertion point cannot be located.","triggerScenarios":"Calling ModuleClassDependcyAdder.Add (triggered by 'abp add-package' / ProjectNugetPackageAdder) on a file whose module class is declared 'internal class', 'public sealed partial class', or where the class declaration was altered so the literal substring 'public class' is absent.","commonSituations":"A module class declared 'public partial class' where 'public class' is split across the partial keyword; an 'internal' module class; a manually edited or auto-formatted file that changed visibility; a generated file that omits the public modifier.","solutions":["Open the target module .cs file and ensure it contains a declaration literally starting with 'public class' (e.g. change 'internal class MyModule : AbpModule' to 'public class MyModule : AbpModule').","Avoid 'public partial class' patterns that break the substring match, or add the [DependsOn] attribute manually above the class declaration.","Re-run 'abp add-package <pkg>' once the declaration matches the expected pattern."],"exampleFix":"// before\ninternal class MyProjectModule : AbpModule { }\n// after\n[DependsOn(typeof(AbpSomePackageModule))]\npublic class MyProjectModule : AbpModule { }","handlingStrategy":"validation","validationCode":"var moduleSrc = File.ReadAllText(moduleFile);\nif (!moduleSrc.Contains(\"public class\", StringComparison.Ordinal))\n{\n    Console.Error.WriteLine($\"{moduleFile} has no 'public class' declaration; add the [DependsOn] manually.\");\n    return;\n}","typeGuard":"static bool HasPublicClassDeclaration(string source) =>\n    source.Contains(\"public class\", StringComparison.Ordinal);","tryCatchPattern":null,"preventionTips":["Keep module classes declared as 'public class' without intervening keywords like 'partial'.","Add [DependsOn] attributes manually in code review rather than relying on the auto-wirer for non-standard declarations."],"tags":["cli","module-system","code-modification","depends-on","parsing"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}