CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2015
    Posts
    3

    Newbie in C sharp/ Microsoft Visio

    Hi Guys,

    I am attempting to run a code to output the username and accountLockoutTime in Active Directory. But I'm facing errors in the initial phases of the code.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication4
    {
        class Program
        {
            public void Main ()
            {
                PrincipleContext ctx = new PrincipleContext (ContextType.Domain "number")
    The error coming is in using "PrincipleContext" :
    1. The type or namespace name "PrincipleContext" could not be found. Are you missing a using directive or an assembly reference? For this I added the System COnfiguration .NET reference and still error

    2. Only assignment, call, increment, decrement and new object expressions can be used as a statement.

  2. #2
    Join Date
    Jun 2015
    Posts
    3

    Re: Newbie in C sharp/ Microsoft Visio

    Also the "number" after domain is a binary number I do not want to disclose so for the purposes of this thread I just wrote number

  3. #3
    Join Date
    Jun 2015
    Posts
    3

    Re: Newbie in C sharp/ Microsoft Visio

    Okay so I've got it to define PrincipleContext but it is not defining ContextType saying that it doesn't exist in the current context?

    What does that mean?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Newbie in C sharp/ Microsoft Visio

    Quote Originally Posted by kiwi101 View Post
    1. The type or namespace name "PrincipleContext" could not be found. Are you missing a using directive or an assembly reference? For this I added the System COnfiguration .NET reference and still error
    System.Configuration has nothing to do with security. When you are using unfamiliar C# classes and need to find which assembly to reference, just look it up in msdn. For each class in msdn, you'll find the Namespace and Reference to use.

    PrincipalContext Class in msdn.

    From the link...

    Namespace: System.DirectoryServices.AccountManagement
    Assembly: System.DirectoryServices.AccountManagement (in System.DirectoryServices.AccountManagement.dll)

  5. #5
    Join Date
    Jan 2010
    Posts
    1,133

    Re: Newbie in C sharp/ Microsoft Visio

    Also, after you add assembly & namespace references as described above, check you code for typos and syntax errors (there are both in the code you posted above):

    PrincipleContext ctx = new PrincipleContext (ContextType.Domain "number")

    should be

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "number");
    Last edited by TheGreatCthulhu; June 23rd, 2015 at 06:56 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured