{"record":{"id":"bbe11ed7a1339c99","repo":"abpframework/abp","slug":"could-not-find-a-class-derived-from-abpmodule-in-t","errorCode":null,"errorMessage":"Could not find a class derived from AbpModule in the project {projectFile}","messagePattern":"Could not find a class 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":274,"sourceCode":"\n        using (DirectoryHelper.ChangeCurrentDirectory(Path.GetDirectoryName(projectFile)))\n        {\n            Logger.LogInformation(\n                $\"Installing '{package.Name}' package to the project '{Path.GetFileNameWithoutExtension(projectFile)}'...\");\n\n            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","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs#L256-L292","documentation":"After installing the NuGet package, ProjectNugetPackageAdder uses ModuleClassFinder.Find(projectFile, \"AbpModule\") to locate the dependency-injection root. If zero classes inheriting AbpModule exist in the project, the [DependsOn] cannot be wired and the CLI throws a CliUsageException naming the project file.","triggerScenarios":"Adding a module package to a non-module project (class library without an AbpModule-derived class), or to a project whose module class is in a different assembly. ModuleClassFinder scans the project's compiled source for ': AbpModule' inheritance and finds none.","commonSituations":"Targeting a plain class library, a test project, or an infrastructure project that intentionally has no module class; module class declared in a referenced assembly, not the current project; first-time setup where the host module has not been created yet.","solutions":["Add a module class to the target project: 'public class MyProjectModule : AbpModule { }' in a file inside the project.","Re-target the command at the project that owns the relevant module class via --project.","If installing into a class library is intentional, add the [DependsOn] manually and the package reference via 'dotnet add package'."],"exampleFix":"// before: project has no AbpModule-derived class\n// after: add Module.cs\npublic class MyLibraryModule : AbpModule\n{\n    public override void ConfigureServices(ServiceConfigurationContext context) { }\n}","handlingStrategy":"validation","validationCode":"var modules = ModuleClassFinder.Find(projectFile, \"AbpModule\");\nif (modules.Count == 0)\n{ Console.Error.WriteLine($\"{projectFile} has no AbpModule-derived class.\"); return; }","typeGuard":"static bool HasSingleModuleClass(string projectFile) =>\n    ModuleClassFinder.Find(projectFile, \"AbpModule\").Count == 1;","tryCatchPattern":null,"preventionTips":["Ensure each project has exactly one AbpModule-derived class before adding packages.","Create the module class as part of project scaffolding."],"tags":["cli","module-system","package-management","nuget","depends-on"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}