When developing webparts within Visual Studio, and using WSPBuilder, I was having some troubles deploying the webpart.
Well, the WSP solution (feature) would deploy OK, but I couldn’t add it to the page.
The error message was :
“Unable to add selected web part(s).”
Within my Visual Studio project, I have a FEATURE.XML :
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="E4AE2E3A-F4EA-4f76-8AB1-1EB10A035129"
Title="SharePointRoot Very Awesome Web Part"
Description="Does lots of awesome things"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Site"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
</ElementManifests>
</Feature>
This then points to the ELEMENTS.XML :
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="WebPartPopulation" Url="_catalogs/wp" RootWebOnly="TRUE">
<File Url="Very_Awesome.webpart" Type="GhostableInLibrary">
<Property Name="Group" Value="SharePointRoot"></Property>
<Property Name="QuickAddGroups" Value="SharePointRoot" />
</File>
</Module>
</Elements>
The corresponding file containing the “real” details for the WEBPART (typename, etc) is VERY_AWESOME.WEBPART :
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="SharePointRoot.VeryAwesome, SharePointRoot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9ddc3289d104dfbe" />
<importErrorMessage>Cannot import SharePointRoot VeryAwesome Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">SharePointRoot VeryAwesome</property>
<property name="Description" type="string">Displays lots of Very Awesome list items</property>
</properties>
</data>
</webPart>
</webParts>
CODE LIBRARY :
I have a Class library within my project – with the specific logic, etc – and the specific namespace and class library name :
namespace SharePointRoot
{
public class VeryAwesome: Microsoft.SharePoint.WebPartPages.WebPart
{…………….
……………. etc.
PROBLEM :
All the plumbing looks correct – I initially realised I had the WRONG PublicKeyToken for the DLL.
The value had been copied from another project – but it’s now correct.
- Re-deploy – and STILL can’t add the WebPart.
- I un-installed the feature using WSPBuilder – and re-deployed it.
- Still got the same error – unable to add selected web part(s).
WTF !!?!
RESOLUTION :
To cut a long story short (well – over an hour of fiddling, poking, IISRESET’ing, etc) – it turned out to be the copied value for the PublicKeyToken.
Or more specifically – the WEBPART file within the Web Part Gallery.
When you retract/delete the solution – the WEBPART file does not get deleted.
And – if you make changes to the WEBPART file – it doesn’t get over-written.
And so – even though I had updated the PublicKeyToken, but it wasn’t actually re-deploying the file.
I only discovered this after I (in desperation) changed the text within the WEBPART – to see if the message box would change – and it didn’t…!
LESSON :
If you’re having troubles with NOT being able to add a webpart, maybe manually delete the WEBPART file from the Web Part Gallery – and try to re-deploy it – especially if you’ve had to change the PublicKeyToken, or TypeName, etc – AFTER it’s been initially deployed.
- Click on Site Actions > Site Settings
- Click Web Parts
- Find the WebPart – and click the “Edit” button (on the right)
- Click “View XML” to see the type name – this is how I noticed the OLD PublicKeyToken value
- Click the button for “Delete Item”
- Re-deploy your WSP from within Visual Studio
- Check the Web Part Gallery to see the updated value/s
Hope that helps – it certainly tricked me for a little bit !
——————————–
Another great post from Mikhail Dikov has a few other pointers and things-to-try…>
Thanks very much, I’ve been looking at this for a couple of days I didn’t know where else to look!
LikeLike
Excellent man!! I was going mad until I found your article! Great work!
LikeLike
Mikhail Dikov,
GREAT! Thank You very very much! 🙂
I changed WSPBuilder versions, recompiled on x86, x64… Well I searched wrong place) Thank You for solution!
LikeLike