1

我正在尝试将 Adusers 列表添加到字典中,但由于某种原因,它适用于名为“a”的 1 个用户,但是对于第二个用户“abcdedf ancdef”,它给了我这个例外,

_COMPlusExceptionCode = 0xe0434f4d

                         if (member != null && !string.IsNullOrEmpty(member.UserName))
                        {
                            string MemberName = member.UserName.ToString().Replace(".", " ");
                            UserList.Add(groupName, MemberName);
                        }

这是我在调试时得到的,不知道去哪里找到解决方案,这是代码

        protected override void CreateChildControls()
    {
        base.CreateChildControls();

        try
        {
            TreeView tree = new TreeView();
            TreeNode groupNode = default(TreeNode);
            List<string> GroupList = new List<string>();
            Dictionary<string, string> UserList = new Dictionary<string, string>();
            List<string> IndividualUserList = new List<string>();

            foreach (SPUser user in SPContext.Current.Web.Users)
            {
                string groupName = FormatUserLogin(user.Name);

                if (!user.IsDomainGroup &&  groupName != "" && groupName != "System Account")
                    IndividualUserList.Add(groupName);

                else if (user.IsDomainGroup && !string.IsNullOrEmpty(groupName) && 
                    Directory.DoesGroupExist(groupName))
                {
                    GroupList.Add(groupName);
                    foreach (ADUser member in Directory.GetUsersFromGroup(groupName))
                    {
                        if (member != null && !string.IsNullOrEmpty(member.UserName))
                        {
                            string MemberName = member.UserName.ToString().Replace(".", " ");
                            UserList.Add(groupName, MemberName);
                        }
                    }
                }
            }

            IndividualUserList.Sort();

            foreach (string Item in IndividualUserList)
            {
                groupNode = new TreeNode(Item);
            }

            foreach (string GroupListItem in GroupList)
            {
                groupNode = new TreeNode(GroupListItem);
                foreach (KeyValuePair<string, string> UserPair in UserList)
                {
                    if (UserPair.Key == GroupListItem)
                    {
                        groupNode.ChildNodes.Add(new TreeNode(UserPair.Value));
                    }
                }
            }

            if (groupNode != null)
            {
                tree.Nodes.Add(groupNode);
                this.Controls.Add(tree);
            } 
            tree.Nodes.Add(groupNode);
        }
        catch (Exception)
        {
            //loggingit
        }
    }
4

0 回答 0