Background: I wrote code that will output all the currently logged in User's Active Directory group names. I want the group name (ex: Acomp_user_BIG) via IdentityReference.Translate instead of the current user's SID's (ex: S-1-5-32-544) returned via IdentityReference.Value.
Here is code that I used:
Public ReadOnly Property Groups As IdentityReferenceCollection
Get
Dim irc As IdentityReferenceCollection
Dim ir As IdentityReference
irc = WindowsIdentity.GetCurrent().Groups
For Each ir In irc
Dim account As IdentityReference = ir.Translate(GetType(NTAccount))
Debug.WriteLine(account.Value)
Next
End Get
End Property
Unfortunately, I get the error on the "End Get":
Warning 1 Property 'Groups' doesn't return a value on all code paths.
A null reference exception could occur at run time when the
result is used.
Any suggestions for fixing this error?