Accessing AD.vb compile error

Dear Experts

I am trying to reproduce \IdentityManager.9.2\OneIdentityManager.9.2\Modules\QBM\dvd\AddOn\SDK\ScriptSamples\07 Expert knowledge\05 Accessing AD.vb , i copied the sample copy into the script.

However, after I tried to compile the database, i got the error "Could not find referenced assembly dll". 

I have run the software loader to import the dll into database, so now i see the green circle on the list

File name : System.DirectoryServices.dll

State : Version OK

File size : 422816

Version : 4.8.3761.0build by: NET48REL1 

What I know anything i did was wrong or anything missing?

  • Did you copy the sample 1:1? The sample "05 Accessing AD.vb" seems to have some bugs.

    1. The name of the referenced DLL System:DirectoryServices.DLL is missing in the references definition.
    2. Another reference to Interop.ActiveDS.dll is missing.

    A fixed version of the code can be found below. (I just fixed it to compile without errors and didn't had the time to test this thoroughly).

    In general, if you need more samples about how to program against AD in .NET there are many samples just some googleing away.

    #If Not SCRIPTDEBUGGER Then
        References System.DirectoryServices.dll
        Imports System.DirectoryServices
    #End If
    
    Public Sub Expert_ADAccess(ByVal strDN As String)
    
        Using adEntry As New DirectoryEntry(strDN)
    
            ' Get property names
            For Each propName As String In adEntry.Properties.PropertyNames
                VID_Write2Log("C:\Test.Log", propName + ": " + ADSProperty_GetValue(adEntry, propName))
            Next
    
            ' Write a property
            adEntry.Properties("Description").Value = "New description"
    
            ' Save changes (if permitted)
            adEntry.CommitChanges()
    
            ' Remove AD property (not clearing but really removing)
            ADSProperty_Clear(adEntry, "Description")
    
        End Using
    
    End Sub
    
    Public Function ADSProperty_GetValue(ByVal adsEntry As DirectoryEntry, ByVal propName As String) As String
        Dim colValues As PropertyValueCollection = adsEntry.Properties(propName)
        Dim strReturn As String = String.Empty
    
        For Each val As Object In colValues
            strReturn = strReturn + val.ToString()
        Next
    
        Return strReturn
    End Function
    
    #If Not SCRIPTDEBUGGER Then
        References Interop.ActiveDS.dll
    #End If
    Public Sub ADSProperty_Clear(ByVal adsEntry As DirectoryEntry, ByVal propName As String)
        Dim adsUser As Object = adsEntry.NativeObject   ' get native object
        Dim adsType As Type = adsUser.GetType()         ' get native type
    
        ' Call PutEx
        adsType.InvokeMember("PutEx", Reflection.BindingFlags.InvokeMethod, Nothing, adsUser, New [Object]() {ActiveDs.ADS_PROPERTY_OPERATION_ENUM.ADS_PROPERTY_CLEAR, "Description", Nothing})
    
        ' Call SetInfo to save values
        adsType.InvokeMember("SetInfo", Reflection.BindingFlags.InvokeMethod, Nothing, adsUser, New [Object]() {})
    End Sub