I am using Visual Studio 2010. When I want to use PrincipalContext Class, the Visual Studio couldn't find the Reference:

enter image description here

I have opened the project with .NET Framework 4 selected and my project was targeting .NET Framework 3.5 in Project Properties.

.NET Framework 3.5+ should have System.DirectoryServices but why this happens?

PS: I am using Application page.

  • Have you added a reference to System.DirectoryServies.AccountManagement in your project? Are you using that namespace in your code file? – TZHX Dec 23 '12 at 7:45
  • There is no "System.DirectoryServies" in Reference List to Add! I have no idea what's happening... – Vahid Dec 23 '12 at 7:48

I think System.DirectoryServices requires an manual reference to System.DirectoryServices.dll which can be done just by right clicking your project in solution explorer -> Add Reference -> in .NET Tab,

select "System.DirectoryServies.AccountManagement".

Now, you should be able to import System.DirectoryServies.AccountManagement namespace.

Adding Reference to System.DirectoryServies.AccountManagement

If you still can't see it like its shown in above picture then you should try adding reference like this,

<add assembly="System.DirectoryServices.AccountManagement, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

It doesn't matter if you are using application page or not, I would recommend you to go through this article for a better understanding of this new class for Directory services.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.