Skip to content

Commit 4d8738f

Browse files
Merge pull request #37 from FrendsPlatform/FSPES-3-AddUserToGroup-empty-groups-issue
Fix KeyNotFoundException when checking empty groups for existing users
2 parents d69bede + 90906c5 commit 4d8738f

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Frends.LDAP.AddUserToGroups/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.1.0] - 2025-08-13
4+
### Fixed
5+
- Fixed KeyNotFoundException when checking empty groups for existing users.
6+
37
## [1.0.1] - 2024-03-01
48
### Fixed
59
- Fixed issue with UserExistsAction parameter when AD returned another error message by adding method to actually check if the user is in the group.

Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/AddUserToGroups.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Threading;
66
using System.Linq;
7+
using System.Collections.Generic;
78

89
namespace Frends.LDAP.AddUserToGroups;
910

@@ -89,7 +90,17 @@ private static bool UserExistsInGroup(LdapConnection connection, string userDn,
8990

9091
if (entry != null)
9192
{
92-
LdapAttribute memberAttr = entry.GetAttribute("member");
93+
LdapAttribute memberAttr;
94+
95+
try
96+
{
97+
memberAttr = entry.GetAttribute("member");
98+
}
99+
catch (KeyNotFoundException)
100+
{
101+
continue;
102+
}
103+
93104
var currentMembers = memberAttr.StringValueArray;
94105
if (currentMembers.Where(e => e == userDn).Any())
95106
return true;

Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups/Frends.LDAP.AddUserToGroups.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net6.0</TargetFrameworks>
5-
<Version>1.0.1</Version>
5+
<Version>1.1.0</Version>
66
<Authors>Frends</Authors>
77
<Copyright>Frends</Copyright>
88
<Company>Frends</Company>

0 commit comments

Comments
 (0)