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

Exception when loading Folder from ListItem #809

Closed
1 task done
FelgeIO opened this issue Apr 3, 2022 · 2 comments
Closed
1 task done

Exception when loading Folder from ListItem #809

FelgeIO opened this issue Apr 3, 2022 · 2 comments
Assignees
Labels
area: model 📐 Related to the core SDK models bug Something isn't working

Comments

@FelgeIO
Copy link
Contributor

FelgeIO commented Apr 3, 2022

Category

  • Bug

Describe the bug

An exception is thrown when properties of a Folder - that is represented by a ListItem - are loaded and/or accessed:

Specify the GraphGet/GraphGetLinq field of the ClassMapping property

Steps to reproduce

The following method can be used to reproduce the issue (provided that at least one ListItem representing a Folder is contained within the list):

public async Task GetFolderChanges(IList list)
{
    var queryOptions = new ChangeQueryOptions() { Add = true, Update = true, Item = true };
    IList<IChange> listChanges = list.GetChanges(queryOptions);

    foreach (var listChange in listChanges)
    {
        if (listChange is IChangeItem changeItem)
        {
	    var itemId = changeItem.ItemId;
            var listItem = list.Items.GetById(itemId);

            if (listItem.IsFolder())
            {
                // Option 1:
                try
                {
                    var folder = await listItem.Folder.GetAsync(f => f.ServerRelativeUrl, f => f.Name, f => f.TimeLastModified);
                    // do something with folder
                }
                catch (Exception ex)
                {
                    // Exception: "Specify the GraphGet/GraphGetLinq field of the ClassMapping property"
                }

                // Option 2:
                try
                {
                    var folder = listItem.Folder;
                    await folder.LoadAsync(f => f.ServerRelativeUrl, f => f.Name, f => f.TimeLastModified);
                    // do something with folder
                }
                catch (Exception ex)
                {
                    // Exception: "Specify the GraphGet/GraphGetLinq field of the ClassMapping property"
                }
            }
        }
    }
}

Presumably, one could also just iterate over a list to find a Folder in order to reproduce the issue .. I simply stumbled upon this while writing some code to process changes of a list.

Expected behavior

When the above code is run for a ListItems representing Files (listItem.IsFile() + listItem.File), everything works as expected: The requested properties (ServerRelativeUrl, Name, TimeLastModified) are loaded correctly and can be accessed. I expect that this would also be the correct behavior for ListItems representing Folders .. but instead, an exception is thrown.

Environment details

  • SDK version: 1.6.0
  • OS: Windows 10
  • SDK used in: Azure Function App (dotnet-isolated)
  • Framework: .NET Framework 6.0
  • Tooling: Visual Studio 2022

Additional context

The logs show that the exception is thrown before the request is even sent to SharePoint.

FelgeIO added a commit to FelgeIO/pnpcore that referenced this issue Apr 3, 2022
Issue ref: pnp#809

- Fixed exception that is thrown when Folder-properties are accessed (and/or loaded) through a corresponding ListItem-object
@jansenbe jansenbe self-assigned this Apr 4, 2022
@jansenbe jansenbe added bug Something isn't working area: model 📐 Related to the core SDK models labels Apr 4, 2022
@jansenbe
Copy link
Contributor

jansenbe commented Apr 4, 2022

Thanks @FelgeIO for using PnP Core SDK and logging this issue...and fix for it 👍

@jansenbe
Copy link
Contributor

jansenbe commented Apr 4, 2022

@FelgeIO : fix has been merged and will appear in next nightly (1.6.7). Thanks for providing this. Will close the issue now, but don't hesitate to re-open or create a new one in case you still experience an issue.

@jansenbe jansenbe closed this as completed Apr 4, 2022
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 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants