abpframework/abp · error · CliUsageException
Could not find a class derived from AbpModule in the project
Error message
Could not find a class derived from AbpModule in the project {projectFile} What it means
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.
Source
Thrown at framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs:274
using (DirectoryHelper.ChangeCurrentDirectory(Path.GetDirectoryName(projectFile)))
{
Logger.LogInformation(
$"Installing '{package.Name}' package to the project '{Path.GetFileNameWithoutExtension(projectFile)}'...");
if (useDotnetCliToInstall)
{
await AddUsingDotnetCli(package, version);
}
else
{
await AddToCsprojManuallyAsync(projectFile, package, version);
}
var moduleFiles = ModuleClassFinder.Find(projectFile, "AbpModule");
if (moduleFiles.Count == 0)
{
throw new CliUsageException(
$"Could not find a class derived from AbpModule in the project {projectFile}");
}
if (moduleFiles.Count > 1)
{
throw new CliUsageException(
$"There are multiple classes derived from AbpModule in the project {projectFile}: " +
moduleFiles.JoinAsString(", "));
}
ModuleClassDependcyAdder.Add(moduleFiles.First(), package.ModuleClass);
}
if (useDotnetCliToInstall && (package.Target == NuGetPackageTarget.Blazor ||
package.Target == NuGetPackageTarget.BlazorServer ||
package.Target == NuGetPackageTarget.BlazorWebAssembly))
{
tryView on GitHub (pinned to 7ed43b1931)
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'.
Example fix
// before: project has no AbpModule-derived class
// after: add Module.cs
public class MyLibraryModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context) { }
} Defensive patterns
Strategy: validation
Validate before calling
var modules = ModuleClassFinder.Find(projectFile, "AbpModule");
if (modules.Count == 0)
{ Console.Error.WriteLine($"{projectFile} has no AbpModule-derived class."); return; } Type guard
static bool HasSingleModuleClass(string projectFile) =>
ModuleClassFinder.Find(projectFile, "AbpModule").Count == 1; Prevention
- Ensure each project has exactly one AbpModule-derived class before adding packages.
- Create the module class as part of project scaffolding.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- There are multiple classes derived from AbpModule in the pro
- "public class" declaration not found!
- Couldn't find any project/solution.
- '{packageName}' nuget package could not be found!
- Package is not found or downloadable!
AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13).
Data as JSON: /api/errors/bbe11ed7a1339c99.
Report an issue: GitHub.