2

In my current production code, we have the following that was working perfectly fine:

XsltListViewWebPart clientInfoWebPart = new XsltListViewWebPart();
clientInfoWebPart.Title = "Client Info";
clientInfoWebPart.WebId = web.ID;
clientInfoWebPart.ListName = clientInfoListSP.ID.ToString("B").ToUpper();
clientInfoWebPart.ChromeType = PartChromeType.TitleOnly;
clientInfoWebPart.Toolbar = "None";
clientInfoWebPart.XmlDefinition = clientInfoHomePageview.GetViewXml();
clientInfoWebPart.ViewGuid = clientInfoHomePageview.ID.ToString("B").ToUpper();
clientInfoWebPart.Hidden = true;
mgrPageManager.AddWebPart(clientInfoWebPart, "Header", 0);
mgrPageManager.SaveChanges(clientInfoWebPart);

However, after SP1 was installed, we got this issue, in the Save Changes line.

(Object reference not set to an instance of an object.) System.NullReferenceException   
 at Microsoft.SharePoint.WebPartPages.BaseXsltListWebPart.EnsureView()    
 at Microsoft.SharePoint.WebPartPages.XsltListViewWebPart.get_View()    
 at Microsoft.SharePoint.WebPartPages.SPWebPartManager.SaveChangesCore(SPLayoutProperties layoutProperties, Boolean httpGet, Boolean saveCompressed, Boolean skipRightsCheck, Boolean skipSafeAgainstScriptCheck, WebPartTypeInfo& newTypeId, Byte[]& newAllUsersProperties, Byte[]& newPerUserProperties, String[]& newLinks)    
 at Microsoft.SharePoint.WebPartPages.SPWebPartManager.SaveChangesInternal(SPLayoutProperties layoutProperties, Boolean skipRightsCheck, Boolean skipSafeAgainstScriptCheck)    
 at Microsoft.SharePoint.WebPartPages.SPWebPartManager.SaveChanges(Guid storageKey)    
 at Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager.SaveChanges(WebPart webPart)    

question, its, whats happening here? how can I fix it? Do I need the save changes? why was it working without throwing the exception PRE-SP1 and now its failing!?

1

I heard back from our engineers, they have suggested that you remove this if you do not care about the ViewGuid. This should then not throw an exception. They are investigating further on this..

clientInfoWebPart.ViewGuid = clientInfoHomePageview.ID.ToString("B").ToUpper();
  • this didnt fix the problem, however removing the save changes fixed it, apparently, when adding webpart, save changes is not needed (after SP1), code was working PRE-SP1 – Luis Valencia Jun 16 '14 at 9:10
1

Removing the call to SPLimitedWebPartManager.SaveChanges fixes it, but I can find no way of using SPLimitedWebPartManager.MoveWebPart anymore - since it requires SaveChanges to be called for it to work. There was not a problem in my code in SP2010, nor SP2013; until SP1 was installed.

1

I'm not yet allowed to create a comment, that's why I have to write my comment as an answer (I'm sorry for that). Wanted to inform you guys, that I had a problem, when just removing the ViewGuid property value. I then ended up with a corrupt view (link "new discussion" disappeared from listviewwebpart in my case). Removing the SaveChanges did the fix for mee too then. Thanks for that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.