40373

GroupPrincipal.IsMemberOf always returns false

I have a function that checks if a group is a member of a group. I have 2 variations of the function, neither work as expected:

public bool IsGroupGroupMember(GroupPrincipal gp, GroupPrincipal pgp) { return gp.IsMemberOf(pgp); }

AND

public bool IsGroupGroupMember(GroupPrincipal gp, GroupPrincipal pgp) { if (gp != null && pgp != null) { return pgp.Members.Contains(gp); } else { return false; } }

Both look promising, however always return false. When it comes time to call the GroupPrincipal.save method, an object already exists error is thrown.

I ran a foreach loop to get the names of the members of the parent group, and compared with the new member name to be added and there is no doubt the member does exist.

I could use LINQ to do string comparison on name, but its not ideal.

What? If anything am I doing wrong? Is there a better method to determine if a group exists in a group.

Using framework 3.5 - thanks in advance

Answer1:

I understand it's kind of late, but for future references you might want to try this.

public bool IsGroupGroupMember(GroupPrincipal gp, GroupPrincipal pgp) { return gp.GetMembers(true).Contains(pgp); }

Answer2:

I hope this helps the next developer with the same issue:

Solved it like this:

public bool IsGroupGroupMember(GroupPrincipal gp, GroupPrincipal pgp) { PrincipalSearchResult<Principal> result = gp.GetGroups(); Principal grp = result.Where(g => g.Sid == pgp.Sid).FirstOrDefault(); if (grp == null) { return false; } else { return true; } }

I still don't know why the methods in my original question didn't work as expected.

Answer3:

In my case the problem was related to the size of the group as also described here.

Recommend

  • How do I Invite a user by email to a Lync 2010 chat session using the API?
  • What is the best Rails caching option for largely static pages with a dynamic header
  • protobuf-net concurrent performance issue in TakeLock
  • Passing dynamic list of primitives to a Java method
  • What is the point of MESI on Intel 64 and IA-32
  • How to merge two tables and transpose rows to columns
  • why isn't the natural height of a Frame updated immediately?
  • Exclusive access established by another Thread Java smartcardio
  • Visual Studio not stopping on an exception being thrown
  • Extracting individual digits from a float
  • How do I add a File Type Association in a Windows Phone 8.1 app manifest?
  • Issue with routerLink directive
  • C#: Import/Export Settings into/from a File
  • How can I set a binding to a Combox in a UserControl?
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • Groovy: Unexpected token “:”
  • AJAX Html Editor Extender upload image appearing blank
  • How to create a file in java without a extension
  • Does CUDA 5 support STL or THRUST inside the device code?
  • MySQL WHERE-condition in procedure ignored
  • Trying to switch camera back to front but getting exception
  • In LanguageTool, how do you create a dictionary and use it for spell checking?
  • AT Commands to Send SMS not working in Windows 8.1
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Free memory of cv::Mat loaded using FileStorage API
  • Hits per day in Google Big Query
  • Angular 2 constructor injection vs direct access
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How do I configure my settings file to work with unit tests?
  • Change div Background jquery
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How does Linux kernel interrupt the application?
  • Linking SubReports Without LinkChild/LinkMaster
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Is it possible to post an object from jquery to bottle.py?
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Programmatically clearing map cache
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?