From df016dd55c3816fc6d8566a7cec51db3258ee69c Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 30 Jan 2026 10:35:00 +0800 Subject: [PATCH] Bug fix https://github.com/2dust/v2rayN/issues/8720 --- v2rayN/ServiceLib/Common/Extension.cs | 24 +++++++++++++++++++ .../Manager/ActionPrecheckManager.cs | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) 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) {