diff --git a/v2rayN/ServiceLib/Common/Extension.cs b/v2rayN/ServiceLib/Common/Extension.cs
index b6ee8154..1403d127 100644
--- a/v2rayN/ServiceLib/Common/Extension.cs
+++ b/v2rayN/ServiceLib/Common/Extension.cs
@@ -94,4 +94,28 @@ public static class Extension
{
return configType is EConfigType.Custom or EConfigType.PolicyGroup or EConfigType.ProxyChain;
}
+
+ ///
+ /// Safely adds elements from a collection to the list. Does nothing if the source is null.
+ ///
+ public static void AddRangeSafe(this ICollection destination, IEnumerable? source)
+ {
+ ArgumentNullException.ThrowIfNull(destination);
+
+ if (source is null)
+ {
+ return;
+ }
+
+ if (destination is List list)
+ {
+ list.AddRange(source);
+ return;
+ }
+
+ foreach (var item in source)
+ {
+ destination.Add(item);
+ }
+ }
}
diff --git a/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs b/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs
index 74e5f5ef..965335cc 100644
--- a/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs
+++ b/v2rayN/ServiceLib/Manager/ActionPrecheckManager.cs
@@ -218,8 +218,8 @@ public class ActionPrecheckManager
var childIds = new List();
var subItems = await ProfileGroupItemManager.GetSubChildProfileItems(group);
- childIds.AddRange(subItems.Select(p => p.IndexId));
- childIds.AddRange(Utils.String2List(group.ChildItems));
+ childIds.AddRangeSafe(subItems.Select(p => p.IndexId));
+ childIds.AddRangeSafe(Utils.String2List(group.ChildItems));
foreach (var child in childIds)
{