DevX HomePage

Troubleshooting Web Parts and Deployment

While SharePoint has become tremendously popular precisely because it makes so many laborious tasks so easy, deployment of Web parts can be surprisingly thorny. The trick lies in knowing what STSADM, the command line tool generally used for installing Web parts from a CAB file, is looking for and making sure it's all packaged up properly.
his isn't the article that I set out to write. While researching another article (coming soon) I soon realized there just isn't a lot of good material on how to troubleshoot Web part deployment, or even precisely how Web part deployment via STSADM even works. This article is designed to explain the moving parts of the deployment process and describe what can go wrong. Hopefully, it will help a few people get their implementations up and running more smoothly.

Why Deploy with STSADM?
Before getting too deeply involved in fixing STSADM Web part deployments, it's important to understand what STSADM is and why it's a good platform for troubleshooting Web part deployment.

STSADM is a 'utility knife' type of tool that ships as a part of Windows SharePoint Services. It does a wide range of things from site creation to Web part pack installation. If you have SharePoint Services, you already have this utility; it is typically found in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\Bin.

Alternative tools such as WPPackager just add additional complexity to the process by wrapping the installation in a Windows Installer file. Worse, these tools don't really gain you anything. At their core they're still using the same installation process by running STSADM or calling the Windows SharePoint Services object model calls that roughly equate to the STSADM options.

But whether you choose to download one of these tools or stick with the somewhat plain but very functional STSADM, learning how STSADM deploys Web parts is very valuable.




Understanding the CAB File
In order to troubleshoot Web parts and deployment you must first understand how the process works. This means understanding what STSADM does to the CAB files that you create for it. The CAB files that STSADM wants are not special other than the fact that they contain a manifest.xml file which contains the instructions that STSADM needs to set up the Web part.

There are two basic sections to the manifest.xml file (see Figure 1). The first, which falls under the <Assemblies> tag, contains the DLLs, supporting files, and configuration entries that are made by STSADM. The second section, DWP Files, falls under the <DwpFiles> tag and contains all of the DWP files for the package. DWP files are what the user sees when adding a Web part to the site. They contain the title to display, the description for the hover text, the assembly to load and what the properties are that should be loaded into the Web part. They are the configuration part of a Web part, whereas the assembly is the code that is running.

Figure 1. Get in the CAB: The contents of the CAB file are shown.
In the <Assemblies> tag there is a set of <Assembly> tags. Each tag in the set has a FileName attribute that defines the name of the assembly being described. This file should be packaged inside the CAB file.

If the assembly contains the Web parts then it should have a <SafeControls> tag (note plural), which encloses one or more <SafeControl> tags (note singular), each of which has an attribute for Namespace and TypeName. The Namespace is the namespace that the type belongs in and the TypeName is the specific name of the type in the namespace to make safe (or a * to indicate that all types in the specified Namespace are good). These <SafeControl> tags are used to create the appropriate entries in the web.config file. The web.config file entries are nearly identical except they reference the full name of the assembly.

The <Assembly> tag may also contain a <ClassResources> tag (note plural), which itself encloses one or more <ClassResource> tags (note singular). The <ClassResource> tag has an attribute, FileName, which specifies the name of the file to include as a resource. These files should also be included in the CAB file. Class resources are things like images and JavaScript include files, which the Web part will need to operate correctly.

Assembly tags do not need any sections inside of them. If the tag doesn't have any references inside of it, the assembly is copied just like the other DLLs. This is important when you are referencing other DLLs from your Web part DLL. By adding a separate assembly tag for them you can ensure they get copied during installation so that your DLL can use the referenced DLLs during run time.

The next major section is the DWP Files section. The <DwpFiles> tag has one or more <DwpFile> tags in it. Each of the <DwpFile> tags has an attribute, FileName, which contains the name of the DWP file to install. DWP files themselves are XML files as well. They contain a <Title> tag, which holds the text to display in the Web Part menu when a user tries to add a Web part. The files also contain a <Description> tag that contains the text that will be displayed in a tool tip when the user hovers over the Web part in the Add Web Part pane.

The DWP file also contains information necessary to load the DLL, which is where the code for the Web part really is. It contains an <Assembly> tag that references the DLL that the Web part type is loaded from. If the DLL has been strong named, which I recommend, the assembly tag must provide a fully specified code base including the public key, which makes this tag particularly troublesome. It is easy to overlook this step since Visual Studio will create the DWP file without the strong named code base and you will be able to install the Web part to the site without warning, however, users won't be able to use the Web part.

The next attribute <TypeName> isn't as difficult, it just describes the fully qualified name of the Web part type including the namespace.

In addition, a DWP file may contain additional tags. A DWP file can contain tags for each of the public properties that are exposed by the Web part. If your Web part has a property named MyPublicProperty then a tag of <MyPublicProperty> in the DWP file will populate that property. This allows you to create multiple DWP files, appearing as multiple Web parts, which all use the same fundamental DLL and type but use different properties. You can even set the value of hidden properties that do not appear in the tool pane.

Figure 2. Charting it Out: Though the workflow is fairly simple, this process ends in errors fairly frequently. Knowing how STSADM works is your best defense against problems.
Understanding What STSADM Does
Sure, STSADM extracts the CAB file and installs the Web part—but how precisely does it do that? The answer is that it depends. It depends on whether you use the global install or not.

Basically, STSADM does three things:

Figure 2 walks you through the workflow for the STSADM.

If you read between the lines you'll realize that the safe controls in the web.config are updated. This in turn means that the ASP.NET worker process will reset itself because it is designed to reset when the web.config file is changed. Ultimately, you'll need to be careful about installing Web parts during the middle of the day, as they'll force a momentary interruption in service.




Common Problems
Now that you have a foundation for how things work, in the following sections I'll tear apart common errors and what their causes are.

Installation
Here are some of the problems that you can run into when trying to install a Web part pack:

Running
One of the most frustrating things about SharePoint is not being able to determine what the problem is when a Web part can't be displayed. Generally you get the message that the Web part isn't registered as safe but you may get a handful of other messages including that the Web part has caused an error. Here are a few things to check:

SharePoint Web parts aren't the easiest things to troubleshoot, however, with a bit of knowledge and a bit of patience you can make them work.

Robert Bogue, MCSE (NT4/W2K), MCSA:Security, A+, Network+, Server+, I-Net+, IT Project+, E-Biz+, CDIA+ has contributed to more than 100 book projects and numerous other publishing projects. He was recently honored to become a Microsoft MVP for Microsoft Commerce Server and before that Microsoft Windows Servers-Networking. Robert blogs at http://www.thorprojects.com/blog.


DevX is a division of Internet.com.
© Copyright 2010 Internet.com. All Rights Reserved. Legal Notices