SharePoint 2013 – The specified view is invalid in call to LimitedWebPartManager.AddWebPart

My problem Today I tried to add a web part to a page using the following code: This gave me a "The specified view is invalid" Exception on the AddWebPart call. Your Solution Then I moved the following line: resulting in and the web part was added to the page with the correct view.