Open Closed

Error when Save and Generate Class with Abp Suite #10312


User avatar
0
kwanp created

Hi I got Error when Save and Generate Class with Abp Suite 10.0.2

Follow this tutorial https://abp.io/docs/latest/tutorials/microservice/part-03?UI=NG&DB=EF

i already try to fix it manual but when regenerate it back to error again

Provide us with the following info:

  • Template: microservice
  • Created ABP Studio Version: 2.1.6
  • Current ABP Studio Version: 2.1.6
  • Multi-Tenancy: Yes
  • UI Framework: angular
  • Theme: leptonx
  • Theme Style: system
  • Theme Menu Placement: side
  • Database Provider: ef
  • Database Management System: sqlserver
  • Mobile Framework: none
  • Public Website: No
  • Social Login: Yes
  • Include Tests: Yes
  • Dynamic Localization: Yes
  • Kubernetes Configuration: Yes
  • Grafana Dashboard: Yes
  • Use Local References: No
  • Aspire: No
  • Optional Modules:
    • GDPR
    • TextTemplateManagement
    • AuditLogging
    • OpenIddictAdmin
  • Selected Languages: English, Thai
  • Default Language: English
  • Create Command: abp new CloudCrm2 -t microservice --ui-framework angular --database-provider ef --database-management-system sqlserver --theme leptonx --skip-migration --skip-migrator --without-cms-kit --dont-run-install-libs --dont-run-bundling -no-file-management -no-language-management
  • Exception message and full stack trace: Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/Services/Dtos/Products/ProductCreateDto.cs(10,19): error CS0103: The name 'ProductConsts' does not exist in the current context [/Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/CloudCrm2.CatalogService.Contracts.csproj] /Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/Services/Dtos/Products/ProductCreateDto.cs(10,64): error CS0103: The name 'ProductConsts' does not exist in the current context [/Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/CloudCrm2.CatalogService.Contracts.csproj] /Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/Services/Dtos/Products/ProductUpdateDto.cs(11,19): error CS0103: The name 'ProductConsts' does not exist in the current context [/Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/CloudCrm2.CatalogService.Contracts.csproj] /Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/Services/Dtos/Products/ProductUpdateDto.cs(11,64): error CS0103: The name 'ProductConsts' does not exist in the current context [/Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/CloudCrm2.CatalogService.Contracts.csproj] /Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/Services/Dtos/Products/ProductCreateDto.cs(14,12): error CS0103: The name 'ProductConsts' does not exist in the current context [/Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/CloudCrm2.CatalogService.Contracts.csproj] /Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/Services/Dtos/Products/ProductCreateDto.cs(14,47): error CS0103: The name 'ProductConsts' does not exist in the current context [/Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/CloudCrm2.CatalogService.Contracts.csproj] /Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/Services/Dtos/Products/ProductUpdateDto.cs(15,12): error CS0103: The name 'ProductConsts' does not exist in the current context [/Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/CloudCrm2.CatalogService.Contracts.csproj] /Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/Services/Dtos/Products/ProductUpdateDto.cs(15,47): error CS0103: The name 'ProductConsts' does not exist in the current context [/Users/kwanp/Documents/Projects/CloudCrm2/services/catalog/CloudCrm2.CatalogService.Contracts/CloudCrm2.CatalogService.Contracts.csproj] 0 Warning(s) 8 Error(s)

  • Steps to reproduce the issue:

Thank you


1 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution

    The error means that ABP Suite generated DTOs referencing a ProductConsts class, but that class does not exist in your solution (or is in a wrong namespace). When Suite tries to run DB migration, it first runs dotnet build, which fails with those ProductConsts errors.

    Create the ProductConsts class once in the correct namespace. After that, you can safely use Save and Generate again; Suite will keep using this class instead of deleting it.

    1. Find the expected namespace

    1. Open
      /services/catalog/CloudCrm2.CatalogService.Contracts/Services/Dtos/Products/ProductCreateDto.cs
    2. At the top of the file, you will see something like:
    using System.ComponentModel.DataAnnotations;
       using ...; // there should be a using for the namespace where ProductConsts is expected
    

    For example it may look like:

    using CloudCrm2.CatalogService.Products;
    

    Note this namespace – ProductConsts must live there.

    2. Add ProductConsts.cs in the Domain.Shared project

    1. In the CloudCrm2.CatalogService.Domain.Shared project, create a folder that matches the namespace used above, typically:
    /services/catalog/CloudCrm2.CatalogService.Domain.Shared/Products/ProductConsts.cs
    
    1. Add the following class (set the namespace to match the using you saw in the DTO):
    namespace CloudCrm2.CatalogService.Products // <-- adjust to match your using
       {
           public static class ProductConsts
           {
               // Taken from your ABP Suite configuration:
               public const int NameMinLength = 2;
               public const int NameMaxLength = 120;
    
               // If Description has a max length in Suite, add it here:
               public const int DescriptionMaxLength = 1000; // or the value you configured
    
               public const int StockCountMinValue = 0;
               public const int StockCountMaxValue = 999999;
           }
       }
    
    1. Ensure the file is included in the project (right‑click the CloudCrm2.CatalogService.Domain.Shared project → Reload or Rebuild; in SDK‑style projects all *.cs files are included automatically).

    3. Rebuild and re-run ABP Suite

    1. From the solution root, run:
    dotnet build
    

    It should now succeed without the ProductConsts errors.

    1. Open ABP Suite from ABP Studio again, go to your CloudCrm2.CatalogService CRUD page and click Save and Generate.
      Since ProductConsts now exists as a normal class in the expected namespace, Suite’s regeneration will compile fine and DB migration should complete.

    If you later change the validation values (min/max lengths, ranges) in ABP Suite, remember to update the constants in ProductConsts to keep them in sync.

    1. Sources
    • Microservice tutorial you followed (shows the same Product entity created with ABP Suite and then built/migrated):
      https://abp.io/docs/latest/tutorials/microservice/part-03?UI=NG&DB=EF

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

Learn More, Pay Less
33% OFF
All Trainings!
Get Your Deal
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.2.0-preview. Updated on January 09, 2026, 07:22
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.