SubPointSolutions / spmeta2

SharePoint artifact provision for .NET platform. Supports SharePoint Online, SharePoint 2019, 2016 and 2013 via CSOM/SSOM.
http://subpointsolutions.com/spmeta2
133 stars 56 forks source link

WebpartModelHandler null reference exception #1118

Closed andreasblueher closed 6 years ago

andreasblueher commented 6 years ago

Hello,

I ran into an issue with the following method.

https://github.com/SubPointSolutions/spmeta2/blob/f54e29be0724aecc3ee90fbd7c58fdccc4f8eb82/SPMeta2/SPMeta2.CSOM/ModelHandlers/WebPartModelHandler.cs#L109-L115

While trying to create a webpartpage and placing a webpart in one step the first one didn't proceed and there this method when trying to access listItemModelHost.HostListItem returned null. I think it would be better to check for null aswell and throw an exception so people know that the item/page couldn't be found.

Do you agree?

SubPointSupport commented 6 years ago

@andreasblueher looks like a bug.

The story about this piece of code is that GetCurrentPageFile() extracts File from different places - either from HostFile if present or falling back to HostListItem.File. This is because depending on the target web page type (webpart/wiki/publishing page) and where it was (library/list), the source File would be made available in different places by SharePoint API itself. Normally, it should not fail. If it fails, then we may have a new scenarios not covered by code/tests or something weird happened before getting to this particular point. Either way, bug for sure.

To move this forward, we would need a failing model to replicate the exact scenario. Could you please share the following:

SubPointSupport commented 6 years ago

Implemented in dev, raising a proper exception.

@andreasblueher by looking into source code, it is not supposed to fail. If you could share failing model then it would help to nail down the problem further. Closing for the time being, feel free to reopen adding troubled model/definition here.