Sitefinity 4.4 ArgumentOutOfRangeException when getting user

Posted by Community Admin on 03-Aug-2018 21:05

Sitefinity 4.4 ArgumentOutOfRangeException when getting users roles

All Replies

Posted by Community Admin on 14-May-2012 00:00

Hello,
This used to work in the previous version, but with the new upgrade to 4.4 it appears to not work anymore. My code is meant to retrieve all of the roles that a particular user has. Calling the method returns an IQueryable<Role>. When I check the Count on the IQueryable, I get an ArgumentOutOfRangeException. The full message below:

The compiled query cache contains an entry for this query, but it's result converter is not producing the required type : 'Telerik.Sitefinity.Security.Model.Role, Telerik.Sitefinity.Model, Version=4.4.2117.0, Culture=neutral, PublicKeyToken=b28c218413bdf563'.
Parameter name: targetType
Actual value was System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

Here is the code I wrote:

RoleManager appRoleManager = RoleManager.GetManager("AppRoles");
RoleManager defaultRoleManager = RoleManager.GetManager("Default");
UserManager userManager = UserManager.GetManager();
Guid userKey = (Guid)Membership.GetUser().ProviderUserKey;
  
if (HCUserInfo.IsInRole("Administrators"))
    string roleNames = "";
    IQueryable<Role> appRoles = appRoleManager.GetRolesForUser(userKey);
    IQueryable<Role> defaultRoles = defaultRoleManager.GetRolesForUser(userKey);
    User user;
    if (defaultRoles != null && defaultRoles.Count<Role>() > 0) 
    
        if (defaultRoles != null)
        
            foreach (Role role in defaultRoles)
            
                roleNames += "'" + role.Name + "',";
            
        
    

Posted by Community Admin on 15-May-2012 00:00

Nevermind,
I found the problem. Turns out the user I used didn't have any roles in that particular provider after all. Fixed the problem by just reversing the if statement and placing an else clause.

This thread is closed