Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFile/IListItem - CheckIfUserHasPermissionsAsync Throws ->System.NullReferenceException: #1097

Closed
1 task done
Cro-Bagy opened this issue Feb 13, 2023 · 2 comments
Closed
1 task done
Assignees
Labels
area: model 📐 Related to the core SDK models question Further information is requested

Comments

@Cro-Bagy
Copy link

Cro-Bagy commented Feb 13, 2023

Category

  • Bug

Describe the bug

CheckIfUserHasPermissionAsync for IListItem (coming from IFile) throws "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

It's happening in
ListItem.cs file line -> 1679 - > Method "BuildGetUserEffectivePermissionsApiCall"

Seems that the Parent.Parent is not a list, it's a Web object.
var parentList = Parent.Parent as List;
Then it fails during string formatting because parentList is null

Steps to reproduce

var file = await clientContext.Web.GetFileByServerRelativeUrlAsync(relativeUrl, 
            f => f.ListItemAllFields.QueryProperties(p => p.ParentList), f => f.Parent);
var item = file.ListItemAllFields;

//BUG in PnP.Core - Workaround - Uncomment if you want that it works
//item.Parent.Parent = item.ParentList;

return await item.CheckIfUserHasPermissionsAsync(spUser.UserPrincipalName, permission);

Expected behavior

To not do the workaround

var file = await clientContext.Web.GetFileByServerRelativeUrlAsync(relativeUrl, 
            f => f.ListItemAllFields.QueryProperties(p => p.ParentList), f => f.Parent);
var item = file.ListItemAllFields;

return await item.CheckIfUserHasPermissionsAsync(spUser.UserPrincipalName, permission);

Environment details (development & target environment)

  • SDK version: 1.8.0
  • OS: Windows 10
  • SDK used in: Console App & ASP.Net Web app
  • Framework: net6.0
  • Tooling: VS 2022
@jansenbe
Copy link
Contributor

Thanks for using PnP Core SDK and reporting this @denbg9fe , I'll have a look.

@jansenbe jansenbe self-assigned this Feb 13, 2023
@jansenbe jansenbe added question Further information is requested area: model 📐 Related to the core SDK models labels Feb 13, 2023
jansenbe added a commit that referenced this issue Feb 13, 2023
@jansenbe
Copy link
Contributor

@denbg9fe : already fixed this one :-) Fix will appear in next nightly (version 1.8.100 or higher). Closing this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants