{"id":1018,"date":"2010-05-08T20:58:16","date_gmt":"2010-05-09T01:58:16","guid":{"rendered":"http:\/\/blogs.devhorizon.com\/reza\/?p=1018"},"modified":"2010-05-13T07:43:16","modified_gmt":"2010-05-13T12:43:16","slug":"sharepoint-administration-toolkit-getbyprincipalid-method-call","status":"publish","type":"post","link":"https:\/\/blogs.devhorizon.com\/reza\/2010\/05\/08\/sharepoint-administration-toolkit-getbyprincipalid-method-call\/","title":{"rendered":"SharePoint Administration Toolkit &#038; GetByPrincipalId() Method Call"},"content":{"rendered":"<p><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions.PNG\" title=\"checkeffectivepermissions.PNG\"><\/a><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions_norole.PNG\" title=\"checkeffectivepermissions_norole.PNG\"><\/a><a href=\"http:\/\/blogs.msdn.com\/sharepoint\/archive\/2009\/08\/27\/announcing-the-fourth-release-of-the-microsoft-sharepoint-administration-toolkit.aspx\">SharePoint Administration Toolkit<\/a> ships with a very handy tool that&#8217;s installed at web site level (SPWeb) named Check Effective Permissions. Essentially, this tool checks to see if a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spprincipal.aspx\">SPPrincipal <\/a>object has got permissions to any objects within the current web site and all the sub sites that <strong><u>inherit<\/u> <\/strong>from the current site. It also provides other permission related reports such as anonymous access level or other factors that effect the level of access for the given SPPrincipal object.<\/p>\n<p><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions.PNG\" title=\"checkeffectivepermissions.PNG\"><\/a><\/p>\n<p><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions.PNG\" title=\"checkeffectivepermissions.PNG\"><\/a><\/p>\n<p><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions.PNG\" title=\"checkeffectivepermissions.PNG\"><img decoding=\"async\" src=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions.thumbnail.PNG\" alt=\"checkeffectivepermissions.PNG\" \/><\/a>\u00a0<\/p>\n<p>Sometimes when you use the tool, it throws the &#8220;<em>Value does not fall within the expected range<\/em>&#8221; exception on SPRoleAssignmentCollection.GetByPrincipalId(Int32 principalId) method call. See the stack trace below:<\/p>\n<p>[Xml]<\/p>\n<p>Value does not fall within the expected range; at Microsoft.SharePoint.SPRoleAssignmentCollection.GetByPrincipalId(Int32 principalId)<br \/>\nat Microsoft.SharePoint.SPRoleAssignmentCollection.GetAssignmentByPrincipal(SPPrincipal principalToFind)<br \/>\nat Microsoft.Office.Server.SecurityReport.SecurityReportAccountManager.CheckPermissions(Object contextObject, String username, AclUIMode aclType)<br \/>\nat Microsoft.Office.Server.SecurityReport.SecurityReportAccount.BtnCheck_Click(Object sender, EventArgs e)<\/p>\n<p>&#8230;.<\/p>\n<p>[\/Xml]<\/p>\n<p>In our case, since the exception was only thrown for some SPPrincipal objects, I did a quick analysis and found out that if the SPPrincipal has no role assigned to it (see the figure below), it blows up the API call. I know this may sound kinda bizzare. Why do we need an SPPrincipal without having a role assgined to it? For a number of reasons. For example, you may need to create the groups in advance and assign the permissions later. Or, maybe the\u00a0groups are auto-generated by an import process, but something has gone wrong when assigning the roles. As a result, some groups do not have roles assigned to them.<\/p>\n<p><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions_norole.PNG\" title=\"checkeffectivepermissions_norole.PNG\"><img decoding=\"async\" src=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions_norole.thumbnail.PNG\" alt=\"checkeffectivepermissions_norole.PNG\" \/><\/a><\/p>\n<p><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions_norole.PNG\" title=\"checkeffectivepermissions_norole.PNG\"><\/a><\/p>\n<p><a href=\"https:\/\/blogs.devhorizon.com\/reza\/wp-content\/uploads\/2010\/05\/checkeffectivepermissions_norole.PNG\" title=\"checkeffectivepermissions_norole.PNG\"><\/a><\/p>\n<p>By the way, people have reported other similar issues on the bottom of this <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.sproleassignmentcollection.getassignmentbyprincipal.aspx\">page<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SharePoint Administration Toolkit ships with a very handy tool that&#8217;s installed at web site level (SPWeb) named Check Effective Permissions. Essentially, this tool checks to see if a SPPrincipal object has got permissions to any objects within the current web site and all the sub sites that inherit from the current site. It also provides [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-1018","post","type-post","status-publish","format-standard","hentry","category-moss-2007"],"_links":{"self":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/1018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/comments?post=1018"}],"version-history":[{"count":0,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/1018\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/media?parent=1018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/categories?post=1018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/tags?post=1018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}