title: The (&(objectCategory=user)(|(CN=)(sAMAccountName=))) search filter is invalid
body: <blockquote>
    <p>The (&amp;(objectCategory=user)(|(CN=)(sAMAccountName=))) search filter is
    invalid.</p>
  </blockquote>
  
  <p>Can someone tell me under what circumstances does this error show up ? </p>
  
  <p>I am trying to publish my web application through Visual Studio. I runs fine on the local host but gives this error after publishing. </p>
  
  <pre><code> public static string[] ldapUserQuery(string userName, string[] desiredProps)
      {
          //  Establishes path for query. In this case sap.corp
          string queryPath = "LDAP://DC=SAP,DC=CORP";
  
          //  Used to establish desiredProps from within the function, but now it can be passed in.
          //  This was kept in here as an example of what the desiredProps should look like when
          //  passing it in.
          //
          //  Desired pros are the LDAP attributes to be returned.
          /*
              string[] desiredProps = new string[]
              {
                  //"givenName",    //  first name
                  //"sn",           //  last name
                  //"mail"          //  email
              };
          */
  
          //  establishes the proper length of the array to be returned.
          string[] returnVal = new string[desiredProps.Length];
  
          //  Creates objects for performing the Query.
          DirectoryEntry dirEntry = new DirectoryEntry();
          DirectorySearcher dirSearcher = new DirectorySearcher();
          SearchResult result;
  
          //  dirEntry is used for establishing the connection for the query
          dirEntry.Path = queryPath;
          dirEntry.AuthenticationType = AuthenticationTypes.Secure;
  
          //  dirSearcher is the query itself.
          dirSearcher.SearchRoot = dirEntry;
          dirSearcher.Filter = string.Format("(&amp;(objectCategory=user)(|(CN={0})(sAMAccountName={0})))", userName);
  
          //  executes the query.
          result = dirSearcher.FindOne();
  
          //  handle the result of the query.
          if (result != null)
          {
              //  if the query was successful, then dig through the returned information
              //  and set found objects that match the desiredProps to the returnVal object.
              for (int i = 0; i &lt; desiredProps.Length; i++)
              {
                  //  if the desiredProps has a bad attribute name, just give it the placeholder
                  //  and move along.
                  if (result.Properties[desiredProps[i]] != null)
                  {
                      returnVal[i] = result.GetDirectoryEntry().Properties[desiredProps[i]].Value.ToString();
                  }
                  //else
                  //{
                  //    returnVal[i] = GlobalVars.placeHolder;
                  //}
              }
          }
  </code></pre>