【问题标题】:OutOfMemoryException on adding to AD group添加到 AD 组时出现 OutOfMemoryException
【发布时间】:2015-07-09 10:53:12
【问题描述】:

我有一个作为 Windows 任务运行的控制台应用程序。

其中一项操作是将计算机添加到 AD 组。

下面的代码就是这样做的:

public static bool AddToGroup(string machineName, string groupName)
        {
            using (
                var context = new PrincipalContext(
                    ContextType.Domain,
                    Helper.GetAppSetting("Domain"),
                    Helper.GetAppSetting("ServiceAccountLogonName"),
                    Helper.GetAppSetting("ServiceAccountPassword")))
            {
                using (var group = GroupPrincipal.FindByIdentity(context, groupName))
                {
                    using (var computer = ComputerPrincipal.FindByIdentity(context, machineName))
                    {
                        if (group == null || computer == null)
                        {
                            return false;
                        }
                        group.Members.Add(computer);
                        group.Save();
                        return true;
                    }
                }
            }
        }

此功能和任务一直在运行,没有问题。

此任务失败一次,并显示以下错误消息:异常 类型“System.OutOfMemoryException”被抛出。

是因为正在搜索的机器或组的原因吗? 代码中是否存在使其易受 OutOfMemoryExceptions 影响的问题?

【问题讨论】:

    标签: c# active-directory out-of-memory active-directory-group


    【解决方案1】:

    我在电脑上发现了问题。

    运行可执行文件的驱动器上的页面文件设置为无。

    我愿意在这里听到其他可能的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-30
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 2012-10-05
      相关资源
      最近更新 更多