Starts in:
2 DAYS
8 HRS
50 MIN
13 SEC
Starts in:
2 D
8 H
50 M
13 S
Open Closed

abp suite: cannot parse enum file with xmldoc while creating an enum property for an entity #2139


User avatar
0
hillin created
  • ABP Framework version: v4.4.4
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Steps to reproduce the issue:
  • use CRUD generator to create an entity
  • create an enum property for the entity
  • select an enum file which contains xmldocs for its members, e.g.
public enum MyEnum 
{
   ///<summary>Value1</summary>
   Value1,
   ///<summary>Value2</summary>
   Value2,
}
  • apb suite reports error: Cannot parse the enum file: An item with the same key has already been added. Key: /// <summary>

12 Answer(s)
  • User Avatar
    0
    hillin created

    After removing the xmldoc and try to save and generate the entity, abp suite reports:

    Cannot populate enum localizations! Error code: EN0004. System.NullReferenceException: Object reference not set to an instance of an object.
       at Volo.Abp.Suite.Areas.AbpSuite.CrudPageGenerator.Commands.EntityGenerateCommand.Qu5cDTUwlI()
    
  • User Avatar
    0
    hillin created

    After replacing the enum property with an int type, generating the entity reports the following error:

    Error occurred on DB migration step! Make sure the project is compiled and working. Command output: Build started...
    Build failed. Use dotnet build to see the errors.
    

    Turns out the generated EntityRepositoryTestsclass in the EntityFrameworkCore.Tests project, and the EntityApplicationTests class in the Application.Tests project does not compile. They have an excessive %%class-attributes%% text generated above the class signature. E.g.:

    namespace MyProject.Entities
    {   %%class-attributes%%
        public class EntityRepositoryTests : MyProjectEntityFrameworkCoreTestBase
        {
    
  • User Avatar
    0
    hillin created

    After unchecking the Create unit & integration tests option for the entity, generating the entity still reports the same error:

    Error occurred on DB migration step! Make sure the project is compiled and working. Command output: Build started...
    Build failed. Use dotnet build to see the errors.
    

    However dotnet build runs just fine!

    Edit: this one is because the aspnetcore project is running (without debugging). Closing the running project and finally the generation worked.

  • User Avatar
    0
    hillin created

    Some more minor problems:

    • The enum members has to have values, otherwise the generated angular proxy is incorrect:
    public enum MyEnum 
    {
       Value1,
       Value2,
    }
    

    turns into

    export enum MyEnum 
    {
       Value1 =,
       Value2 =,
    }
    
  • User Avatar
    0
    hillin created

    With all these issues being said, I think the CRUD generator feature of abp suite is not really in a good shape, you have to be very careful and avoid some problematic features to get it working.

  • User Avatar
    0
    alper created
    Support Team Director

    hi,

    you need to set enum values (not only for Suite also for the best practises) otherwise the order change of items will make the values change in the future. so pls set value to your enums

  • User Avatar
    0
    hillin created

    Thanks Albert, I can see it's a good idea to set enum values. Can you have a look at the other issues described above?

  • User Avatar
    0
    alper created
    Support Team Director

    Can you try a new entity to test and create a new enum as below, and tell me the result

    public enum Level 
    {
       Low = 1,
       Medium = 2,
       High = 3
    }
    
  • User Avatar
    0
    hillin created

    Thanks Albert, as I already replied above, it works very well with enums that have values, and I fully understand why the values matter.

    However I've also addressed a few other issues related to the CRUD generation feature of abp suite, namely:

    And even more minor issues as I step further into the jungles, such as the angular UI pages it generates does not compile in typescript strict mode. So my main point is, the CRUD generation feature is somewhat stale nowadays, I'd expect an overhaul before it can really work in modern projects. I'm sorry as some of these points are placed under an unrelated topic.

  • User Avatar
    0
    jkrause created

    The entire ABP Suite cannot handle file scoped namespaces, so that is a bigger issue. With the move to .NET 6 for ABP v5 it would be essential to have this working, e.g. after refactoring your code Suite does not understand it at all.

    • So file (re)generation fails, as it cannot find the region where to place the (updated) code
    • Loading files leaves the namespace blank as it cannot parse it

    As an added feedback on the enums, if the enum is not of type int, everything else fails, this also applies to flagged enums. I am not sure if ABP Suite CRUD generator supports flags enums but I had to refactor it to explicit int values to work.

    In addition, the enum values are added to JSON as: Enum:EnumType:EnumValue but if you look at https://docs.abp.io/en/abp/5.0/UI/AspNetCore/Tag-Helpers/Form-elements#label-localization-1 it says it looks in the localization texts with EnumType.EnumValue so right now I have untranslated enums everywhere.

    Note: It would be very helpful to have a separate v5 issues thread like exists for v4.4 Note: If these issues should be posted on Github instead let us know :)

  • User Avatar
    0
    alper created
    Support Team Director

    the scoped namespace is not supported yet in Suite. but we'll try to support it we already have an internal issue about that. and here's the v5 issues https://support.abp.io/QA/Questions/2209/

  • User Avatar
    0
    jkrause created

    Thank you @albert!

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06