-
Notifications
You must be signed in to change notification settings - Fork 194
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
PnP.Core.ClientException: Specify the GraphGet/GraphGetLinq field of the ClassMapping property #631
Comments
@SPDEVGUY : Once you've loaded data you need to use So your code would be like this: var url = "https://contoso.sharepoint.com";
var context = await Pnp.CreateAsync(new Uri(url));
log.Log($"Loaded context for {ctx.Site.Id}");
var site = ctx.Site;
await site.GetAsync(p => p.RootWeb);
var rw = site.RootWeb;
await rw.GetAsync(p => p.Webs);
foreach (var w in rw.Webs.AsRequested())
{
} You could also optimize above code a little bit as rootweb is always loaded by default + possibly you can save a roundtrip by loading additional RootWeb properties during PnPContext initialization (see https://pnp.github.io/pnpcore/using-the-sdk/basics-context.html). Taking that in account below code will do 2 server roundtrips to achieve the same result: var options = new PnPContextOptions()
{
AdditionalWebPropertiesOnCreate =
new Expression<Func<IWeb, object>>[]
{
w => w.Webs
}
};
var url = "https://contoso.sharepoint.com";
var context = await Pnp.CreateAsync(new Uri(url), options);
log.Log($"Loaded context for {ctx.Site.Id}");
foreach (var w in context.Web.Webs.AsRequested())
{
// Use the web
} |
I think still we have an issue here, because below code throws an exception: var webs = context.Web.Webs.ToList(); To my understanding, it shouldn't throw and should query subwebs instead. |
Category
Describe the bug
Unhelpful exception when querying sub-webs:
PnP.Core.ClientException: Specify the GraphGet/GraphGetLinq field of the ClassMapping property
Attempting to follow documentation to enumerate sub-webs:
https://pnp.github.io/pnpcore/using-the-sdk/webs-intro.html#getting-sub-webs
Error thrown:
Source code:
Essential bits:
`
var url = "https://contoso.sharepoint.com";
var context = await Pnp.CreateAsync(new Uri(url));
log.Log($"Loaded context for {ctx.Site.Id}");
var site = ctx.Site;
await site.GetAsync(p => p.RootWeb);
var rw = site.RootWeb;
await rw.GetAsync(p => p.Webs);
foreach (var w in rw.Webs) << Exception accessing rw.Webs property.
`
Steps to reproduce
Code above.
Can I not use PnPContext.Site.RootWeb.Webs with the foreach?
Expected behavior
When accessing Context.Site.RootWeb.Webs I expect to be able to enumerate the webs within that site after doing the GetAsync calls as per the documentation.
Throw informative exception or improve documentation?
Environment details (development & target environment)
Additional context
Thanks for your contribution! Sharing is caring.
The text was updated successfully, but these errors were encountered: