Просмотр исходного кода

fix: GetAssemblies().SelectMany(u => u.GetTypes()) 改为 App.EffectiveTypes

AppDomain.CurrentDomain.GetAssemblies().SelectMany(u => u.GetTypes()) 可能会抛 could not load type 异常,App.EffectiveTypes 中会捕捉异常处理
许俊杰 2 лет назад
Родитель
Сommit
0267ba2eb1
1 измененных файлов с 1 добавлено и 7 удалено
  1. 1 7
      Admin.NET/Admin.NET.Core/Service/Const/SysConstService.cs

+ 1 - 7
Admin.NET/Admin.NET.Core/Service/Const/SysConstService.cs

@@ -77,12 +77,6 @@ public class SysConstService : IDynamicApiController, ITransient
     /// <returns></returns>
     private List<Type> GetConstAttributeList()
     {
-#if NET6_0
-        return AppDomain.CurrentDomain.GetAssemblies().SelectMany(u => u.GetTypes())
-            .Where(u => u.CustomAttributes.Any(c => c.AttributeType == typeof(ConstAttribute))).ToList();
-#else
-        return AppDomain.CurrentDomain.GetAssemblies().SelectMany(u => u.GetExportedTypes())
-            .Where(u => u.CustomAttributes.Any(c => c.AttributeType == typeof(ConstAttribute))).ToList();
-#endif
+        return App.EffectiveTypes.Where(u => u.CustomAttributes.Any(c => c.AttributeType == typeof(ConstAttribute))).ToList();
     }
 }