{"action":"created","issue":{"url":"https://api.github.com/repos/OfficeDev/PnP-Sites-Core/issues/167","repository_url":"https://api.github.com/repos/OfficeDev/PnP-Sites-Core","labels_url":"https://api.github.com/repos/OfficeDev/PnP-Sites-Core/issues/167/labels{/name}","comments_url":"https://api.github.com/repos/OfficeDev/PnP-Sites-Core/issues/167/comments","events_url":"https://api.github.com/repos/OfficeDev/PnP-Sites-Core/issues/167/events","html_url":"https://github.com/OfficeDev/PnP-Sites-Core/issues/167","id":115287515,"number":167,"title":"Error: Cannot add a role assignment with empty role definition binding collection.","user":{"login":"rfjschouten","id":13015367,"avatar_url":"https://avatars.githubusercontent.com/u/13015367?v=3","gravatar_id":"","url":"https://api.github.com/users/rfjschouten","html_url":"https://github.com/rfjschouten","followers_url":"https://api.github.com/users/rfjschouten/followers","following_url":"https://api.github.com/users/rfjschouten/following{/other_user}","gists_url":"https://api.github.com/users/rfjschouten/gists{/gist_id}","starred_url":"https://api.github.com/users/rfjschouten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rfjschouten/subscriptions","organizations_url":"https://api.github.com/users/rfjschouten/orgs","repos_url":"https://api.github.com/users/rfjschouten/repos","events_url":"https://api.github.com/users/rfjschouten/events{/privacy}","received_events_url":"https://api.github.com/users/rfjschouten/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-05T13:52:14Z","updated_at":"2016-04-18T16:12:55Z","closed_at":null,"body":"I extracted a template using web.GetProvisioningTemplate. The web use has some lists with broken permissions. The extracted template, when saved as xml, contains the correct security tag with role assignments. When I try to apply the template to a new web, I get an exception:\r\n\r\nCannot add a role assignment with empty role definition binding collection."},"comment":{"url":"https://api.github.com/repos/OfficeDev/PnP-Sites-Core/issues/comments/211450395","html_url":"https://github.com/OfficeDev/PnP-Sites-Core/issues/167#issuecomment-211450395","issue_url":"https://api.github.com/repos/OfficeDev/PnP-Sites-Core/issues/167","id":211450395,"user":{"login":"statto1974","id":4395914,"avatar_url":"https://avatars.githubusercontent.com/u/4395914?v=3","gravatar_id":"","url":"https://api.github.com/users/statto1974","html_url":"https://github.com/statto1974","followers_url":"https://api.github.com/users/statto1974/followers","following_url":"https://api.github.com/users/statto1974/following{/other_user}","gists_url":"https://api.github.com/users/statto1974/gists{/gist_id}","starred_url":"https://api.github.com/users/statto1974/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/statto1974/subscriptions","organizations_url":"https://api.github.com/users/statto1974/orgs","repos_url":"https://api.github.com/users/statto1974/repos","events_url":"https://api.github.com/users/statto1974/events{/privacy}","received_events_url":"https://api.github.com/users/statto1974/received_events","type":"User","site_admin":false},"created_at":"2016-04-18T16:12:55Z","updated_at":"2016-04-18T16:12:55Z","body":"This is to do with the code in SecurableObjectExtensions.cs (OfficeDevPnp.Core > Framework > Provisioning > ObjectHandlers > Extensions)\r\n\r\nThe code below \r\n```\r\nvar roleDefinitionBindingCollection = new RoleDefinitionBindingCollection(context);\r\nvar roleDefinition = webRoleDefinitions.FirstOrDefault(r => r.Name == roleAssignment.RoleDefinition);\r\n\r\nif (roleDefinition != null)\r\n{\r\n    roleDefinitionBindingCollection.Add(roleDefinition);\r\n}\r\n\r\nsecurable.RoleAssignments.Add(principal, roleDefinitionBindingCollection);\r\n```\r\n\r\nShould be \r\n \r\n```\r\nvar roleDefinition = webRoleDefinitions.FirstOrDefault(r => r.Name == roleAssignment.RoleDefinition);\r\n\r\nif (roleDefinition != null)\r\n{\r\n  var roleDefinitionBindingCollection = new RoleDefinitionBindingCollection(context);\r\n   roleDefinitionBindingCollection.Add(roleDefinition);\r\n  securable.RoleAssignments.Add(principal, roleDefinitionBindingCollection);\r\n}\r\n```\r\n\r\nBefore if it couldn't find the RoleDefinition in the target web it was still creating a RoleDefinitionBindingCollection, but adding it as empty which is throwing the error.\r\n\r\nNot sure why the RoleDefinition doesn't exist and that may need to be investigated further, but this worked for me."}}