Conversion from type '_ComObject' to type 'String' is not valid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dodol135
    New Member
    • Jan 2009
    • 3

    Conversion from type '_ComObject' to type 'String' is not valid

    Hi guys i got following error while i am running my program
    here is the code scratch where i got an exception :

    Try
    Dim de As New DirectoryEntry( "LDAP://xxx/dc=xxx,dc=com", "aaa", "secret")
    Dim MyAttributes As PropertyCollect ion
    Dim MyAttributeName As String
    Dim myValue As String
    Dim MyAttributeValu es As PropertyValueCo llection
    MyAttributes = de.Properties


    For Each MyAttributeName In MyAttributes.Pr opertyNames
    MyAttributeValu es = MyAttributes(My AttributeName)
    Console.WriteLi ne("------------------------------")
    For Each myValue In MyAttributeValu es
    Console.WriteLi ne(CType(MyAttr ibuteName, String) & " : " & CType(myValue, String))
    Next
    Next
    Catch ex As Exception
    Console.WriteLi ne("ex: " + ex.Message)
    End Try

    Where is the wrong section ?
    please help me guys
    any help would be totally appreciated ....
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by dodol135
    ...
    Where is the wrong section ?
    please help me guys
    any help would be totally appreciated ....
    Use e.StackTrace instead of e.Message to get the exact line number.

    Comment

    • dodol135
      New Member
      • Jan 2009
      • 3

      #3
      OK i'm sorry
      here is the line where i got exception :

      For Each myValue In MyAttributeValu es

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        myValue is a String and the runtime has just told you that the values in MyAttributeValu es are _ComObjects type(whatever that is).
        Better declare Dim myValue As Object instead.

        Comment

        • dodol135
          New Member
          • Jan 2009
          • 3

          #5
          OK, but the main problem is what should i do to manage this error
          changing myValue with object is doesnt solve the problem either
          because __Comtype is not convertible to string,
          and i need to convert to string for listing all field that exist in particular active directory ....
          any suggestion ?

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            The object class has a ToString method. If those objects implemented it correctly then you should get what you want from the ToString.

            Comment

            • jg007
              Contributor
              • Mar 2008
              • 283

              #7
              If I recall correctly had a pretty similar error when accessing AD from VB and it was because I was accessing a collection of objects ( Memberof ) and I just had to ammend it to do a 'For each' on member of.

              Comment

              Working...