Return PrincipalSearchResult AsQueryable over Web API RRS feed

  • Question

  • User-1845223160 posted


    I have this strange issue. I got this working:

    public IQueryable<Principal> GetEmployees()
        UserPrincipal userSearcher = new UserPrincipal(GetPrincipalContext());            
        userSearcher.Name = "*";
        PrincipalSearcher ps = new PrincipalSearcher();
        ps.QueryFilter = userSearcher;
        PrincipalSearchResult<Principal> results = ps.FindAll();
        return results.AsQueryable();

    To get it work I had to do this in the global.asax:

    GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

    Now I ofcource want to return other type of objects over the web api also. So I tried to code the Groups:

    public IQueryable<Principal> GetGroups()
        GroupPrincipal groupSearcher = new GroupPrincipal(GetPrincipalContext());            
        groupSearcher.Name = "*";
        PrincipalSearcher ps = new PrincipalSearcher();            
        ps.QueryFilter = groupSearcher;
        PrincipalSearchResult<Principal> results = ps.FindAll();            
        return results.AsQueryable();

    It's quite simular to the code for the users, only it's not working... Strangely enough.. The error starts like this:

    {"Message":"An error has occurred.","ExceptionMessage":"
    The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
    "Message":"An error has occurred.","ExceptionMessage":
    "Kan ikke hente informasjon om domenet (1355).",
    ved System.DirectoryServices.AccountManagement.Utils.GetDcName(String computerName, String domainName, String siteName, Int32 flags)\r\n   
    ved System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo()\r\n   

    I have read a lot of articles and forums but can not find the solution. Grabing a single group works fine:

    public IHttpActionResult GetGroup(string id)
        var group = GroupPrincipal.FindByIdentity(GetPrincipalContext(), id);
        if (group == null)
            return NotFound();
        return Ok(group);

    Any Idea? Why can't I grab a IQueryable of groups like I can with a IQueryable of Users?


    Sunday, August 30, 2015 7:55 PM

All replies

  • User100579902 posted

    any other tips?

    Tuesday, September 1, 2015 8:58 AM