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 6920161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:06:45+00:00 2026-05-27T10:06:45+00:00

I am try to create extension of principal for organizationalUnit using this code below

  • 0

I am try to create extension of principal for organizationalUnit using this code below

[DirectoryRdnPrefix("OU")]
[DirectoryObjectClass("organizationalUnit")]
public class OrganizationalUnitPrincipal : Principal
{
    public OrganizationalUnitPrincipal(PrincipalContext Context_p)
    {
        PropertyInfo contextRaw = this.GetType().BaseType.GetProperty("ContextRaw",
            BindingFlags.Instance | BindingFlags.NonPublic);
        contextRaw.SetValue(this, Context_p, null);
    }
}

But it throws the following error:

System.ArgumentException: Persisted Principal objects cannot be used as query filters.

This error occurs when I try retrieve organizationalUnit attributes and properties.

Can this work or not?

I want to achieve the same as show on this page http://msdn.microsoft.com/en-us/site/bb384372

  • 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-05-27T10:06:46+00:00Added an answer on May 27, 2026 at 10:06 am

    On the theorical point of view, I think that what you want to do has no sense. It’s explained in the article you point, but it’s not so clear. The concept of Principal is based on the Directory Schema wich discribe objects you can add to ActiveDirectory.

    The Principal, AuthenticablePrincipal, UserPrincipal, ComputerPrincipal, and GroupPrincipal classes can all be extended to create custom objects that extend the object model.

    But in LDAP in general and it’s the case in Active-Directory the class organizationalUnit is not a subclass of the user class, but just a subclass of the top class.

    In other words : on the conceptual point of view you can note that a Principal is kind of user (Yes in Microsoft point of view computers are users, they open sessions onto the domain like the users) and organizationalUnit is a kind of organizational box (like a directory in a file system), so the second one do not extent the first one.


    Edited

    Here is a subclass of DirectoryEntry that do what you want :

    class ClsOrganizationalUnit : DirectoryEntry
    {
      private DirectoryEntry de;
    
      public string Description
      {
        get { return (string)de.Properties["description"][0]; }
        set { de.Properties["description"].Value = value;
              de.CommitChanges();
            }
      }
    
      public ClsOrganizationalUnit(string dn, string username, string password)
      {
        de = new DirectoryEntry(dn, username, password);
      }
    
    
    }
    
    class Program
    {
      static void Main(string[] args)
      {
        ClsOrganizationalUnit ou = new ClsOrganizationalUnit("LDAP://192.168.183.100:389/ou=Monou,dc=dom,dc=fr", "jpb", "pwd");
    
        /* Set the attribute */
        ou.Description = "The description you want";
        Console.WriteLine("Here is your OU description : {0}", ou.Description);
    
        /* Remove the attribute */
        ou.Description = null;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to create an extension method for the File class, I get
I try to create a multi-threaded singleton pattern class. Header: class HL{ public: static
So I try to create some wrapper around boost.extension functions for class creation. So
I tried to create this HtmlHelper method: namespace Power.WebUx.Helpers { public static class HtmlHelperExtensions
I try to create a very simple app using windows API. I've done some
I'm working on an extension for office using Interop assemblies, as part of this
If I create an extension method for my entity objects and try to use
I am making an extension. public static MvcHtmlString Image(this HtmlHelper helper, string src, object
I try to create a new file inside a JSP and try to save
I try to create a thread in QT, can declare, create and start it,

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.