locked
The type or namespace name 'DirectoryEntry' could not be found RRS feed

  • Question

  • User1016820894 posted

    I am using VS 2019 and building a aspx web page that will retrieve information on the use account from directory services (see code below.

    I am getting an error on the red lines below: The type or namespace name 'DirectoryEntry' could not be found (are you missing a using directive or an assembly reference?).

    I have the namespace for Systrem.Directoryservices in the code so I am not sure why I am getting the error.

    Code:

    <%@ Page Language="C#" %>
    <%@Import Namespace="System"%>;
    <%@Import Namespace="System.Configuration"%>;
    <%@Import Namespace="System.Collections"%>;
    <%@Import Namespace="System.DirectoryServices"%>;
    <%@Import Namespace="System.DirectoryServices.AccountManagement"%>;


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    userid = GetHTTPContext();
    GetADGroups(userid);

    public SortedList GetADGroups(string loginName)
    {

      List<string> userNestedMembership = new List<string>(); 
       
        if (string.IsNullOrEmpty(loginName))
            throw new ArgumentException("The loginName should not be empty");

        SortedList ADGroups = new SortedList();

        int backSlash = loginName.IndexOf("\\");
        string userName = backSlash > 0 ? loginName.Substring(backSlash + 1) : loginName;

        DirectoryEntry domainConnection = new DirectoryEntry();
        domainConnection.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Secure;
        DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://xxxdomain");
        DirectorySearcher samSearcher = new DirectorySearcher(directoryEntry);
        samSearcher.SearchRoot = domainConnection;
        
      
    }

    Sunday, June 21, 2020 11:56 PM

All replies

  • User1535942433 posted

    Hi baldwinjohn,

    Do you have add a reference of System.DirectoryServices?

    Adding the line Imports... is not sufficient, you also have to add a reference.

    1.Right click on References under your project in the Solution Explorer

    2.Click on Add Reference.

    3.Select System.DirectoryServices.

    If you have problems,you could post more details to us.

    Best regards,

    Yijing Sun

    Monday, June 22, 2020 3:21 AM
  • User1016820894 posted

    Yes I have the reference for System.DirectoryServices in my project.

    Now I am getting "The type or namespace name 'DirectoryServices' does not exist in the namespace 'System'"

    Monday, June 22, 2020 8:13 PM
  • User1535942433 posted

    Hi baldwinjohn,

    Accroding to your description,as far as I think,you have used the wrong DirectoryServices package.

    I suggest you could download  the package and add the reference again.

    You could download in this.

    Best regards,

    Yijing Sun

    Tuesday, June 23, 2020 2:07 AM