everytime exception occures "Cannot add a role assignment with empty role definition binding collection " , I tried all the solution from other sources still facing same issue..please help.. my code is as below
 
 
- internal bool AssignPermission(ClientContext p_Context ,SPList MicrosoftDestinationList, Folder DestinationFolder,File DestinationFile,ConcurrentBag<SPRoleDefinations> p_Permissions )  
- {  
- string f_UserName = null;  
- string f_GrpName = null;  
- bool f_Flag = false;  
- Principal f_Principal = null;  
- RoleDefinition f_RoleDef = null;  
- RDBCollection roleDefBindCol = null;  
- RACollection ItemRoleAssignCollection = null;  
- List<RoleDefinition> SiteRoleDefinationCollection = null;  
- List<string> UserList = null;  
- bool f_SameContext = false;  
- try  
- {  
- #region CHECK CLIENT CONTEXT  
-   
-   
-   
-   
- if (m_WebGroups.Count > 0)  
- {  
- if (m_WebGroups.ElementAt(0).Context.TraceCorrelationId ==p_Context.TraceCorrelationId)  
- f_SameContext = true;  
- }  
- else if (m_WebUsers.Count > 0)  
- {  
- if (m_WebUsers.ElementAt(0).Context.TraceCorrelationId ==p_Context.TraceCorrelationId)  
- f_SameContext = true;  
- }  
- if(!f_SameContext)  
- UserList = GetUsers(p_Context);  
- #endregion  
- try  
- {  
- if (p_Context.HasPendingRequest)  
- p_Context.ExecuteQuery();  
- }  
- catch (Exception){}  
- if(MicrosoftDestinationList!=null)  
- ItemRoleAssignCollection = MicrosoftDestinationList.RoleAssignments;  
- if (DestinationFile != null)  
- ItemRoleAssignCollection = DestinationFile.ListItemAllFields.RoleAssignments;  
- else  
- if (DestinationFolder != null)  
- ItemRoleAssignCollection = DestinationFolder.ListItemAllFields.RoleAssignments;  
-   
-   
- SiteRoleDefinationCollection = m_WebRoleDefinations[p_Context.Web.Url];  
- foreach (SPRoleDefinations f_RoleDefObj in p_Permissions)  
- {  
- try  
- {  
- bool f_RoleAdeed = false;  
-   
- roleDefBindCol = new RDBCollection(p_Context);  
- foreach (SPROle f_Role in f_RoleDefObj.m_Roles)  
- {  
- try  
- {  
-   
- if (f_Role.m_Name == "Limited Access")  
- continue;  
- RoleType f_RoleType = RoleType.None;  
-   
- if (Enum.TryParse(f_Role.m_RoleKind, out f_RoleType))  
- {  
- if (null != SiteRoleDefinationCollection.Where(rd => rd.RoleTypeKind == f_RoleType).FirstOrDefault())  
- {  
- var roledef = p_Context.Web.RoleDefinitions.GetByType(f_RoleType);  
- p_Context.Load(roledef);  
- p_Context.ExecuteQuery();  
-   
-   
- roleDefBindCol.Add(roledef);  
- f_RoleAdeed = true;  
- }  
- else  
- {  
-   
- f_RoleDef = CreateNewRoleDefination(p_Context, f_Role);  
- if(f_RoleDef!=null)  
- roleDefBindCol.Add(f_RoleDef);  
- f_RoleAdeed = true;  
- }  
- if(MicrosoftDestinationList!=null)  
- MicrosoftDestinationList.BreakRoleInheritance(true, false);  
- if (DestinationFile != null)  
- DestinationFile.ListItemAllFields.BreakRoleInheritance(true, false);  
- else  
- if (DestinationFolder != null)  
- DestinationFolder.ListItemAllFields.BreakRoleInheritance(true, false);  
- p_Context.ExecuteQuery();  
- }  
- }  
- catch (Exception ex)  
- { CommonClass.ExLogger.LogError(ClassName, "AssignPermission:: Log 1 :: ", ex); }  
- }  
- if (!f_RoleAdeed)  
- continue;  
-   
- f_Principal = null;  
- if (!f_RoleDefObj.m_Isgroup)  
- {  
- continue;  
-   
-   
-   
-   
-   
-   
- }  
- else  
- {  
- if (CommonClass.UserMappings.Keys.Contains(f_RoleDefObj.m_SpGroupName))  
- {  
- f_GrpName = CommonClass.UserMappings[f_RoleDefObj.m_SpGroupName];  
- f_Principal = m_WebGroups.Where(grp =>grp.Title.ToLower() ==f_GrpName.ToLower()).First();  
- p_Context.Load(f_Principal);  
- p_Context.ExecuteQuery();  
-   
-   
-   
-   
- ItemRoleAssignCollection.Add(f_Principal, roleDefBindCol);  
- p_Context.Load(ItemRoleAssignCollection);  
- if (MicrosoftDestinationList != null)  
- MicrosoftDestinationList.Update();  
- if (DestinationFile != null)  
- DestinationFile.Update();  
- else  
- if (DestinationFolder != null)  
- DestinationFolder.Update();  
- p_Context.ExecuteQuery();  
- f_Flag = true;  
- }  
- }  
-   
- }  
- catch (Exception ex)  
- { CommonClass.ExLogger.LogError(ClassName, "AssignPermission:: Log 2 :: ", ex); }  
- }  
-   
-   
- }  
- catch (Exception ex)  
- { CommonClass.ExLogger.LogError(ClassName, "AssignPermission", ex); }  
- return f_Flag;  
- }