From 66603041292fe9e61dbd19234ff52b8edb61e0ad Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 26 Nov 2025 09:25:06 +0800 Subject: [PATCH] Fix ApplicationPartSorter to handle duplicate assemblies --- .../Abp/AspNetCore/Mvc/ApplicationPartSorter.cs | 3 ++- .../ApplicationPart/ApplicationPartSorter_Tests.cs | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationPartSorter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationPartSorter.cs index d0ba8b98c0..554ec424bd 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationPartSorter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationPartSorter.cs @@ -15,7 +15,8 @@ public static class ApplicationPartSorter { var orderedModuleAssemblies = moduleContainer.Modules .Select((moduleDescriptor, index) => new { moduleDescriptor.Assembly, index }) - .ToDictionary(x => x.Assembly, x => x.index); + .GroupBy(x => x.Assembly) + .ToDictionary(g => g.Key, g => g.First().index); var modulesAssemblies = moduleContainer.Modules.Select(x => x.Assembly).ToList(); var sortedTypes = partManager.ApplicationParts diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationPart/ApplicationPartSorter_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationPart/ApplicationPartSorter_Tests.cs index 829aa23527..c8324e466a 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationPart/ApplicationPartSorter_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationPart/ApplicationPartSorter_Tests.cs @@ -26,6 +26,13 @@ public class ApplicationPartSorter_Tests partManager.ApplicationParts.Add(new AssemblyPart(assembly)); moduleDescriptors.Add(CreateModuleDescriptor(assembly)); } + + var dumplicateAssembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName($"ModuleB.dll"), AssemblyBuilderAccess.Run); + partManager.ApplicationParts.Add(new AssemblyPart(dumplicateAssembly)); + partManager.ApplicationParts.Add(new AssemblyPart(dumplicateAssembly)); + moduleDescriptors.Add(CreateModuleDescriptor(dumplicateAssembly)); + moduleDescriptors.Add(CreateModuleDescriptor(dumplicateAssembly)); + var randomApplicationParts = partManager.ApplicationParts.OrderBy(x => Guid.NewGuid()).ToList(); // Shuffle the parts // Additional part @@ -44,7 +51,7 @@ public class ApplicationPartSorter_Tests ApplicationPartSorter.Sort(partManager, moduleContainer); // Act - partManager.ApplicationParts.Count.ShouldBe(13); // 10 modules + 3 additional parts + partManager.ApplicationParts.Count.ShouldBe(15); // 10 modules + 3 additional parts + 2 duplicate parts var applicationParts = partManager.ApplicationParts.Reverse().ToList(); // Reverse the order to match the expected output @@ -60,7 +67,9 @@ public class ApplicationPartSorter_Tests applicationParts[9].ShouldBeOfType().Assembly.GetName().Name.ShouldStartWith("ModuleA7"); applicationParts[10].ShouldBeOfType().Assembly.GetName().Name.ShouldStartWith("ModuleA8"); applicationParts[11].ShouldBeOfType().Assembly.GetName().Name.ShouldStartWith("ModuleA9"); - applicationParts[12].ShouldBeOfType().Assembly.ShouldBe(typeof(AbpVirtualFileSystemModule).Assembly); + applicationParts[12].ShouldBeOfType().Assembly.GetName().Name.ShouldStartWith("ModuleB"); + applicationParts[13].ShouldBeOfType().Assembly.GetName().Name.ShouldStartWith("ModuleB"); + applicationParts[14].ShouldBeOfType().Assembly.ShouldBe(typeof(AbpVirtualFileSystemModule).Assembly); } private static IModuleContainer CreateFakeModuleContainer(List moduleDescriptors)