"Cannot be indexed because it has no default value" error

Hello,
Please bear with me, I am very new to VB .NET, most of my experience is with vbscript and I get confused real quick in  .NET.

I have a Sub that I found to add an active directory user to a group, but I get an error "Class 'System.DirectoryServices.DirectoryEntry' cannot be indexed because it has no default value"  It gives me this on "Dim group As DirectoryEntry = GetDirectoryEntry(results(0).Path)".  GetDirectoryEntry is a function I created that looks like this:

Public Shared Function GetDirectoryEntry() As DirectoryEntry
        Dim de As DirectoryEntry = New DirectoryEntry("LDAP://tmctrans.com")
        de.AuthenticationType = AuthenticationTypes.Secure
        Return de
    End Function
What do I need to do to correct this?
Public Shared Sub AddUserToGroup(ByVal de As DirectoryEntry, ByVal deUser As DirectoryEntry, ByVal GroupName As String)
        Dim deSearch As DirectorySearcher = New DirectorySearcher()
        deSearch.SearchRoot = de
        deSearch.Filter = "(&(objectClass=group) (cn=" & GroupName & "))"
        Dim results As SearchResultCollection = deSearch.FindAll()
        Dim isGroupMember As Boolean = False
        If results.Count > 0 Then
            Dim group As DirectoryEntry = GetDirectoryEntry(results(0).Path)
            Dim members As Object = group.Invoke("Members", Nothing)
            For Each member As Object In CType(members, IEnumerable)
                Dim x As DirectoryEntry = New DirectoryEntry(member)
                Dim name As String = x.Name
                If name <> deUser.Name Then
                    isGroupMember = False
                Else
                    isGroupMember = True
                    Exit For
                End If
            Next member
            If (Not isGroupMember) Then
                group.Invoke("Add", New Object() {deUser.Path.ToString()})
            End If
            group.Close()
        End If
        Return
    End Sub

Open in new window

LVL 4
w33mhzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PaulHewsCommented:
Dim group As DirectoryEntry = GetDirectoryEntry(results(0).Path)

Why are you passing a parameter to this function, when the definition doesn't call for one.

Try:

Dim group As DirectoryEntry = GetDirectoryEntry()
0
w33mhzAuthor Commented:
Well it was a copy and paste thing off of a website.  
0
PaulHewsCommented:
Also, you should be able to use this method, and remove the function entirely:

Dim group As DirectoryEntry = results(0).GetDirectoryEntry()

SearchResult..::.GetDirectoryEntry Method
http://msdn2.microsoft.com/en-us/library/system.directoryservices.searchresult.getdirectoryentry.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
w33mhzAuthor Commented:
ok thank you I will try that.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.