Getting a Com Exception for unknown reason

1

I am trying to add List of Adusers into a Dictionary but for some reason, it works for 1 user who's name is "a" but then for second user "abcdedf ancdef" its giving me this exception,

_COMPlusExceptionCode = 0xe0434f4d

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

This is what i got while debugging, no clue where to go to find the solution, here's the code

        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
        }
    }
c#
.net
active-directory
treeview
asked on Stack Overflow May 10, 2012 by Muhammad Raja

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0