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"?>
Title="SharePointRoot Very Awesome Web Part"
Description="Does lots of awesome things"
This then points to the ELEMENTS.XML :
<?xml version="1.0" encoding="utf-8" ?>
<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" />
The corresponding file containing the “real” details for the WEBPART (typename, etc) is VERY_AWESOME.WEBPART :
<type name="SharePointRoot.VeryAwesome, SharePointRoot, Version=18.104.22.168, Culture=neutral, PublicKeyToken=9ddc3289d104dfbe" />
<importErrorMessage>Cannot import SharePointRoot VeryAwesome Web Part.</importErrorMessage>
<property name="Title" type="string">SharePointRoot VeryAwesome</property>
<property name="Description" type="string">Displays lots of Very Awesome list items</property>
CODE LIBRARY :
I have a Class library within my project – with the specific logic, etc – and the specific namespace and class library name :
public class VeryAwesome: Microsoft.SharePoint.WebPartPages.WebPart
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).
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…!
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…>