Cannot recognize the XML namespace of this Web Part

In my earlier post Provisioning webparts through feature, we saw how can custom or out of the box web parts be provisioned on a page through visual studio feature.

Note that sometimes using this approach you might stumble on this error “Cannot recognize the XML namespace”

Notice that when ou download the configured web part you would see 2 kinds of namspaces. https://schemas.microsoft.com/WebPart/v2 and https://schemas.microsoft.com/WebPart/v3.  In SharePoint you have two types of webparts, v2 and v3. Both have slightly different syntax

The elements.xml file for v2 would look something like below

    <File Path="Pages\AccessDenied.aspx" Url="AccessDenied.aspx" Type="GhostableInLibrary" ReplaceContent="TRUE" > <AllUsersWebPart WebPartZoneID="MainZone" ID="MeetingSearchWebPart" WebPartOrder="1"> <![CDATA[ <WebPart xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns="https://schemas.microsoft.com/WebPart/v2"> <Title>Access Denied</Title> <FrameType>Default</FrameType> <Description>Allows authors to enter rich text content.</Description> <IsIncluded>true</IsIncluded> <ZoneID>MainZone</ZoneID> <PartOrder>0</PartOrder> <FrameState>Normal</FrameState> <Height /> <Width /> <AllowRemove>true</AllowRemove> <AllowZoneChange>true</AllowZoneChange> <AllowMinimize>true</AllowMinimize> <AllowConnect>true</AllowConnect> <AllowEdit>true</AllowEdit> <AllowHide>true</AllowHide> <IsVisible>true</IsVisible> <DetailLink /> <HelpLink /> <HelpMode>Modeless</HelpMode> <Dir>Default</Dir> <PartImageSmall /> <MissingAssembly>Cannot import this Web Part.</MissingAssembly> <PartImageLarge>/_layouts/15/images/mscontl.gif</PartImageLarge> <IsIncludedFilter /> <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly> <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName> <ContentLink xmlns="https://schemas.microsoft.com/WebPart/v2/ContentEditor" /> <Content xmlns="https://schemas.microsoft.com/WebPart/v2/ContentEditor">&lt;div&gt;​Access Denied.&#160; Please contact Administrator.&lt;/div&gt;</Content> <PartStorage xmlns="https://schemas.microsoft.com/WebPart/v2/ContentEditor" /> </WebPart> ]]> </AllUsersWebPart> </File>

and with v3:

  <File Path="Pages\MeetingSearch.aspx" Url="MeetingSearch.aspx" Type="GhostableInLibrary" ReplaceContent="TRUE" > <AllUsersWebPart WebPartZoneID="MainZone" ID="MeetingSearchWebPart" WebPartOrder="1"> <![CDATA[<webParts> <webPart xmlns="https://schemas.microsoft.com/WebPart/v3"> .. </webPart> </webParts>]]> </AllUsersWebPart>

v3 had extra <webparts> tag and v2 has extra attributes in WebPart tag.