Home > Development, SharePoint Server 2010 > Changing namespace in Visual Studio 2010 might break a SharePoint 2010 webpart project

Changing namespace in Visual Studio 2010 might break a SharePoint 2010 webpart project

I was creating a SharePoint 2010 project in Visual Studio 2010. I’ve selected the Empty Project and then Add New Item and selected the Webpart item (not the Visual Webpart). After doing some coding, for some reason I’ve decided to change the original namespace that Visual Studio had created for me on the webpart class (.cs file). Then I did some more coding and time to test it. I right click on the project name and select Deploy (I love this new feature in VS2010). Everything goes smooth, package is deployed and everything seems fine. So I go to my SharePoint site, Edit the page, Insert a Webpart, select my new custom webpart and when I hit the Add button, for my surprise I got the error below.

And this is the second time around that this happened to me. The first time was a long time ago so I couldn’t remember why. Then it’s time to do some troubleshooting. I’ve verified that the .DLL file was in the GAC, I’ve checked the web.config file to make sure a <SafeControl> entry was created. Everything looks good. Then I check the webpart definintion file in the WebParts gallery and closely looking at the XML I’ve noticed that the namespace was not matching with my webpart class. The original namespace was still showing. So I went back to my Visual Studio project and I’ve opened the .webpart file (see below) that was created for me.

And for my surprise the original namespace was still showing up there. So if you change your namespace after you create a project in VS2010 make sure that in the .webpart file (see below) under the <Metadata> <type> elements, the name attribute has the correct namespace.


01 <?xml version="1.0" encoding="utf-8"?>
02 <webParts>
04 <metaData>
05 <type name="SP2010.WebParts.MembesListingWebPart.MembersListingWebPart, $SharePoint.Project.AssemblyFullName$" />
06 <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
07 </metaData>
08 <data>
09 <properties>
10 <property name="Title" type="string">Members Listing WebPart</property>
11 <property name="Description" type="string">This WebPart lists the members of a site</property>
12 </properties>
13 </data>
14 </webPart>
15 </webParts>


Another change you have to do and this one is a tricky one is on the Visual Studio 2010 SharePointProjectItem.spdata file. This is a file I believe Visual Studio uses internally to package and deploy the solution. But the catch is that it doesn’t show by default, so you have to click on the “Show All Files” button in the Solution Explorer and this file will show inside your WebPart folder (see below). Edit the file and change the Namespace attributes according to your new namespace.

Also, don’t forget in that if you change the namespace, in your project properties, make sure it’s reflected in the Default Namespace field in the Application tab of your Project properties (right-click your project name and select properties).

Hope this will help some people save some troubleshooting time !



  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: