Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:26:28+00:00 2026-06-11T07:26:28+00:00

I have a intranet that needs to run queries for users in the AD

  • 0

I have a intranet that needs to run queries for users in the AD system. I’m trying to connect using a DirectoryEntry() object, then setup a DirectorySearcher() and do a search for users. Boiled down to it’s most basic, my code is like this:

DirectoryEntry directoryObject = new DirectoryEntry("LDAP://RD-HQ/CN=Users,DC=rd-hq,DC=local");
DirectorySearcher ds = new DirectorySearcher(directoryObject);
ds.Filter = ("(&(objectClass=user))");
var test = ds.FindAll();
foreach (SearchResult item in test)
{
}

Weirdly, this works on my development machine when I reference the .NET4.0 version of the System.DirectoryServices DLL, but not in .NET3.5 (where the version of the System.DirectoryServices DLL is v2.0.0.0).

The specific error I get is on the ds.FindAll() method and reads:

Exception Details: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.

Stepping through the code reveals that the directoryObject object is actually not being initialised correctly on the first line. The constructor doesn’t fail, but all the properties are throwing exceptions.

Any ideas what I might be doing wrong? Thanks, I realise this is a bit of a crappy, vague question.


SOLVED

OK, I managed to fix this by using the overload for the DirectoryEntry() constructor that accepted a username and password:

DirectoryEntry directoryObject = new DirectoryEntry("LDAP://RD-HQ/CN=Users,DC=rd-hq,DC=local", "rd-hq.local\mick", "notmypassword");

I’m still not sure why this works differently in the .NET3.5 version versus the .NET4.0 version and will happily mark as correct the answer that can at least help me understand this stuff better.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:26:30+00:00Added an answer on June 11, 2026 at 7:26 am

    The constructor doesn’t fail, but all the properties are throwing exceptions.

    The DirectoryEntry instance will attempt to bind to the directory when you access one of the relevant properties – if this fails the property accessor will throw an exception. This also happens if you attempt to view the properties from the debugger.

    In your above code, the bind happens when ds.FindAll() is called.

    Clearly there is a problem binding to the directory.

    I find it difficult to believe that the .NET Framework version makes a difference; I would strip your code down to a bare-bones sample you’re using identical code and an identical environment for the .NET 3.5 and .NET 4 versions.

    The error message “An operations error occurred” is rather general, but can happen if you don’t have permission to access the directory. So one possibility is that your .NET 3.5 and .NET 4 versions are running under different identities. At least that appears to have been the cause of this similar problem.

    The ErrorCode returned by the DirectoryCOMException might also give a clue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET app that sits on our intranet, using the WindowsIdentity to
I have an intranet site that our customer needs to access both internally and
I have a intranet site running PHP 5 that needs to list a folder
i am coding a pretty large intranet based web system that needs to support
I have an intranet app that needs to know where to print some labels.
We have an intranet site that serves 50.000 users at maximum (generally only a
I have constructed a Swing Application that needs to be run from a browser.
I have an intranet application that needs contact information for various locations on our
I have an MVC 2 app that has a System.Timers.Timer object starting up during
I have an intranet site that loads in IE7 compatibility mode, unless the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.