Freitag, 19. März 2010

Cannot import webpart

Bin gerade an meinen ersten Versuchen mit Sharepoint 2010. Eine neue Instanz und eigene Sitecollections erstellt. Um sich mit den Listen vertraut zu machen wollte ich ein Visual Webpart erstellen und dort ein wenig probieren. Doch das erstellen eines Webparts mit Visual Studio 2010 RC und dem Deployment auf Sharepoint 2010 war nicht so einfach wie ich dachte. Zwar ist das Deployment generel einfacher wie Sharepoint 2007, jedoch gibt es noch ein paar kleine "Bugs". Ein Fehler, welcher mich Stunden gekostet hat war "Cannot import webpart". In einem Blog habe ich ein Vorgehen entdeckt, wie man herausfinden kann, was an einem Webpart fehlerhaft ist, da die Exceptions in Sharepoint nicht gerade aussagekräftig ist.
1. Site actions -> Site settings -> Galleries -> Webparts
Dort muss das Webpart enthalten sein, ist es das nicht, besteht bereits der
Fehler beim Deployment.
2. Wenn man in der Gallery das Webpart direkt anklickt, müsste es sichtbar sein.
Jetzt kann es sein, dass bei Punkt 2 schon eine Fehlermeldung erscheint. Bei mir hat VS 2010 einfach Probleme mit der Versionierung. Hierzu folgendes beachten:
- Feature1.Template.xml, hier muss die Version und Guid die gleiche sein wie in
der AssemblyInfo.cs (.vb)
- [Name].webpart. In dieser Datei befindet sich unter type ein Placeholder,
welcher von VS generiert wird. Am besten diesen ersetzen durch statische
Werte (bei mir wurde hier immer die falsche Version generiert).
$SharePoint.Project.AssemblyFullName$ ersetzen durch ->
[Assemblyname], Version=[meine aktuelle Version], Culture=neutral
When Feature, Webpart und AssemblyInfo Datei die gleiche Version und Id haben, dann einfach Deployment erneut durchführen und manuell nochmals AppPool und IIS neu starten.
Im GAC (Windows -> assemblies) anschliessend nachsehen ob die Assembly kopiert wurde und die richtige Version hat. Im web.config der Sharepoint Webapplikation sollte die Assembly noch registriert sein.

Wenn alle diese Punkte beachtet wurden, sollte man zurück zu Punkt 2 und nochmals in der Webpart Gallery nachsehen, ob man das Webpart darstellen kann. Wenn ja, dann müsste es auch möglich sein das Webpart in der Seite einzufügen.


I am currently doing my first steps in Sharepoint 2010. Installed a new instance and created a site-collection. To get in touch with the lists and different actions, I created a visual webpart and wanted to play around in the code-behind.
But the creation of the webpart with VS 2010 RC and the deployment to Sharepoint 2010 was not that easy as I thought. Although deployment is now easier then Sharepoint 2007, still there seem to be some little "bugs". One error that required hours of bug fixing was "cannot import webpart". In a blog I found a very good introduction with steps to follow, when errors like that happen, because Sharepoint does not throw informative exceptions.
1. site actions -> site settings -> galleries -> webparts
There the webpart must be listed, when you deployed correctly. If it is not
listed, then something went wrong with deployment.
2. When clicking the webpart in the gallery, then the webpart is supposed to
display it's content. Now it is possible, that you already have an error now.
In my case VS 2010 had problems with the different versions. You should consider the following things:
- Feature1.Template.xml, here you need to have the same version as in the
AssemblyInfo.cs (.vb)
- [Name].webpart. In this file you have a placeholder, where VS generates the
version and some other things (in my case a wrong version has been generated).
$SharePoint.Project.AssemblyFullName$ replace with ->
[Assembly-name], Version=[your current version], Culture=neutral
When feature, webpart and assemblyinfo files do have the same version and Id, then deploy again and restart the application pool and iis manually.
In the global assembly cache (Windows -> assemblies) you should check if the assembly was deployed and if it has the correct version number. In the web.config of your sharepoint web-application this assembly is supposed to be registered as well.

When you checked all those things, then go back to number 2 and check once again if you can display the webpart in the gallery. If it is so, then you might be able to insert the webpart to your page.

Keine Kommentare:

Kommentar veröffentlichen