Sitefinity 4.4 ArgumentOutOfRangeException when getting users roles
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 +
"',"
;
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.