{"record":{"id":"f1a82b2aebac5aed","repo":"abpframework/abp","slug":"there-are-multiple-classes-derived-from-abpmodule","errorCode":null,"errorMessage":"There are multiple classes derived from AbpModule in the project {projectFile}: {moduleFiles}","messagePattern":"There are multiple classes derived from AbpModule in the project (.+?): (.+?)","errorType":"exception","errorClass":"CliUsageException","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs","lineNumber":280,"sourceCode":"            if (useDotnetCliToInstall)\n            {\n                await AddUsingDotnetCli(package, version);\n            }\n            else\n            {\n                await AddToCsprojManuallyAsync(projectFile, package, version);\n            }\n\n            var moduleFiles = ModuleClassFinder.Find(projectFile, \"AbpModule\");\n            if (moduleFiles.Count == 0)\n            {\n                throw new CliUsageException(\n                    $\"Could not find a class derived from AbpModule in the project {projectFile}\");\n            }\n\n            if (moduleFiles.Count > 1)\n            {\n                throw new CliUsageException(\n                    $\"There are multiple classes derived from AbpModule in the project {projectFile}: \" +\n                    moduleFiles.JoinAsString(\", \"));\n            }\n\n            ModuleClassDependcyAdder.Add(moduleFiles.First(), package.ModuleClass);\n        }\n\n        if (useDotnetCliToInstall && (package.Target == NuGetPackageTarget.Blazor ||\n                                      package.Target == NuGetPackageTarget.BlazorServer ||\n                                      package.Target == NuGetPackageTarget.BlazorWebAssembly))\n        {\n            try\n            {\n                await RunBundleForBlazorAsync(projectFile);\n            }\n            catch (Exception)\n            {\n                Logger.LogWarning(\"Couldn't run bundle for blazor.\");","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs#L262-L298","documentation":"Symmetric to 208: ModuleClassFinder.Find returns more than one AbpModule-derived class in the project, so the CLI cannot decide which one should receive the [DependsOn] attribute. It throws a CliUsageException enumerating the ambiguous candidate files to surface the conflict.","triggerScenarios":"Adding a package to a project that legitimately has multiple module classes (e.g. a module split into host + child modules), or one where an old module class was not deleted after a rename, producing duplicates that both inherit AbpModule.","commonSituations":"Refactoring that left a stale module file; a project that intentionally defines several module classes (rare but valid); copy-paste creating a duplicate class declaration.","solutions":["Remove or rename the stale module class so only one AbpModule-derived class remains in the project.","If multiple modules are intentional, add the [DependsOn] manually to the correct one and skip the auto-wiring command.","Run 'abp add-package' targeting a more specific project that has a single module class via --project."],"exampleFix":"// before: two AbpModule classes in one project\npublic class OldModule : AbpModule { }\npublic class MyProjectModule : AbpModule { }\n// after\n// (delete OldModule.cs)\npublic class MyProjectModule : AbpModule { }","handlingStrategy":"validation","validationCode":"var modules = ModuleClassFinder.Find(projectFile, \"AbpModule\");\nif (modules.Count > 1)\n{ Console.Error.WriteLine($\"Multiple module classes found: {modules.JoinAsString(\", \")}\"); return; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Delete stale module files after renames so only one module class remains.","Add [DependsOn] manually when a project legitimately has multiple module classes."],"tags":["cli","module-system","package-management","nuget","ambiguity"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}