locked
Exception with DirectoryEntry.Properties RRS feed

  • Question

  • User1334006062 posted
    Hello,

    I'va an exception with some attributes when I try

    Me.Session("dept") = DirEntry.Properties("DP").Value
    System.Runtime.InteropServices.COMException

    Some (like mail, uid) works, but some doesn't. It seems to be a "Format" problem....

    Any idea ?

    Thanks :)
    Thursday, March 2, 2006 9:33 AM

All replies

  • User1354132231 posted
    You will have to dig inside the COMException to the InnerException to see what the underlying issue is.  At this point, it is hard to tell.

    Wednesday, March 8, 2006 5:01 PM
  • User1540266618 posted
    Hi davfranck

    It's always possible that object from which you are trying to read the property, doesn't support it, or more common, doesn't have it set.

    As dunnry writes in his sticky in this forum under "reading attributes" (Common System.DirectoryServices Patterns):

    "One of the most common issues that people run into is getting an error trying to read the attribute when it does not exist.  It is important to understand there is no concept of null attributes in Active Directory - the attribute either exists on the object or it doesn't - it is never null.  This however can be confusing because trying to read a non-existant attribute culminates in a null reference exception in .NET."

    In your case, you could try something like this:
    DirectoryEntry entry = new DirectoryEntry(...);
    using (entry)
    {
        if (entry.Properties.Contains("sn"))
        {
            string lastName = entry.Properties["sn"][0].ToString();
        }
    }
    Hope this helps, best regards, Egil.
    Wednesday, March 8, 2006 7:18 PM