SharePoint Developer Introduction for .NET Developers
http://www.microsoft.com/click/SharePointDeveloper/
Microsoft SharePoint Team Blog
http://blogs.msdn.com/sharepoint/
Troubleshooting Topics
Problem Area: Debugging and Troubleshooting
Problem
When developing against the SharePoint object model on a machine that is not part of a SharePoint farm you receive the error “Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.SharePoint.CoreResource' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly” or another generic error message.
Resolution
The SharePoint object model can only be used when the application is run on a server in the SharePoint farm. It cannot be executed remotely. If it is not possible to run the application on a SharePoint farm server you should investigate using the SharePoint web services instead.
The Windows SharePoint Services and Microsoft Office SharePoint Services web services are documented in the following SDK’s.
SharePoint Server 2007 SDK: Software Development Kit
http://www.microsoft.com/downloads/details.aspx?FamilyId=6D94E307-67D9-41AC-B2D6-0074D6286FA9&displaylang=en
Windows SharePoint Services 3.0: Software Development Kit (SDK)
http://www.microsoft.com/downloads/details.aspx?FamilyID=05e0dd12-8394-402b-8936-a07fe8afaffd&DisplayLang=en
Problem
You receive “The "yourWebPartName" Web Part appears to be causing a problem” or a generic error message when developing a web part.
Cause
Exceptions are caught by SharePoint and a friendly error message is displayed instead of a stack trace.
Resolution
To configure SharePoint to display the full exception needed for debugging make the following changes to your SharePoint site’s web.config file (typically located in /Inetpub/wwwroot/wss/VirtualDirectories/yoursite).
· Find:
· Replace with:
· Find:
· Replace with:
· Find:
· Replace with:
Problem
You receive “Unknown Error” or another generic error message when developing aspx pages beneath _layouts.
Cause
Application pages beneath _layouts have a separate web.config file that needs updated to enable more detailed error messages.
Resolution
Open /Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/LAYOUTS/web.config
Add the following XML block immediately after the
· Find:
· Replace with:
Problem
You are developing a SharePoint component on an XP or Vista client and you need to debug to troubleshoot your component.
Resolution
Enable Visual Studio 2005 or 2008 Remote Debugging to enable remotely setting breakpoints and single step debugging through your code.
A high level overview of how to do this:
· Install the remote debugging components onto the development server (note this doesn’t require a full VS.NET install)
· Run the Visual Studio 2005 Remote Debugger Configuration Wizard on the development server
· Visual Studio 2005 Remote Debugger on the development server
· Install a debug version of your component on to the server along with the symbol files (.pdb). For debugging, deploying to the /bin directory is preferable.
o Note: If you install your assembly to the global assembly cache (GAC) you will need to copy the .pdb to the directory where the assembly is installed.
§ You can find this out from a command line by typing in the following commands:
· cd /windows/assembly
· dir /s YourAssemblyName.dll
· Copy the .pdb files out of your /debug directory to this directory to enable debugging.
· Ensure that debug=”true” is enabled in your SharePoint sites web.config
· Open the project in Visual Studio on your client (ensure this is the exact same version/build of the assembly that is deployed – do not rebuild)
· Click Debug -> Attach to Process -> change the text in the “Qualifier” text box to be the remote server’s name then click the “Refresh” button.
o Ensure that “Managed” is checked in the “Attach To” area.
o Note: If there are connection problems at this point see the following KB articles for additional configuration steps.
§ http://support.microsoft.com/kb/910448 How to implement remote debugging in Visual Studio 2005
§ http://support.microsoft.com/kb/908099 How to turn on remote debugging for Visual Studio 2005 in Windows XP with Service Pack 2
§ http://support.microsoft.com/kb/947252 Error message when you try to use the Remote Debugging Monitor in Visual Studio on a Windows Vista-based computer: "The Windows Firewall is currently blocking remote debugging"
· You should see a list of processes appear. You will need to select w3wp.exe (there may be multiple instances) and click “Attach”.
· Once attached to the correct instance you can set a break point in the code that you need to debug and reproduce the problem on the server.
o For web parts this could be refreshing the page
o For a feature receiver this could be activating or deactivating the feature
o For an event receiver this could be manipulating data in a list (such as adding, deleting, check-in/check-out) etc…
· The full detailed approach of configuring remote debugging: http://msdn.microsoft.com/en-us/library/bt727f1t(VS.80).aspx
Problem
You are trying to call a SharePoint web service but you are receiving SoapException errors.
Resolution
Add a catch handler to your web service call and handle the SoapException. Inside of the Detail property will be more detailed information to assist troubleshooting.
catch (System.Web.Services.Protocols.SoapException se)
{
// se.Detail has more information
}
Problem Area: Memory Leaks
Problem
Your SharePoint site is exhibiting heavy memory usage and is performing slowly or you are experiencing application pool recycles due to out of memory conditions.
Resolution
Please review Roger Lamb’s blog entry “SharePoint 2007 and WSS 3.0 Dispose Patterns by Example” to ensure you are properly utilizing the Dispose method when using the SharePoint object model.
http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx
Problem Area: User Profiles
Problem
When using the SharePoint class UserProfileManager to read user profiles you receive the error “Only an administrator may enumerate through all user profiles”.
Resolution
There is now a hot fix available for this. At the time of this writing the KB article is not published but you can call into Microsoft support and request the fix by number 952294.
Problem Area: Security
Problem
When calling a web service from within a Web Part or an application outside of IIS you receive the following error:
Unhandled Exception: System.Net.WebException: The request failed with HTTP status 401: Unauthorized.
Resolution
The web service needs credentials to be set before making calls.
Examples:
· listService.UseDefaultCredentials = true; // use currently logged on user
· listService.Credentials = new System.Net.NetworkCredential("user", "pass", "domain"); // use specified user
Problem
When developing against the SharePoint object model in an application outside of IIS (service, console, Winforms etc..) you receive the error “FileNotFoundException” when creating an instance of the SPSite object.
Resolution
The user running the application needs to have the following permissions and group membership set:
· The user is a server farm administrator.
· The user has Read and Write permissions on the content database.
· The user is a site collection administrator.
· The user has permissions to access the Windows SharePoint Services site or the SharePoint Server 2007 site through which the code iterates.
Problem Area: VSEWSS
Problem
You receive the error “This solution contains two assemblies with the same name, or the SharePoint server already has an assembly with the specified name.” when deploying a solution using the Visual Studio Extensions for SharePoint (VSEWSS) after you have already deployed it to a different site on the same server.
Resolution
Remove the solution’s assembly from the Global Assembly Cache (GAC).
· Gacutil –uf assemblyName (note: no .dll extension is specified)
· Rename or Remove the feature from “Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES/FeatureName” (note: FeatureName may not be the same as assembly name – look in your manifest.xml to find the correct name)
Problem
When trying to deploy a VSEWSS solution using the Visual Studio “Deploy” command you receive the error “Value does not fall within the expected range.”
Resolution
Remove all projects except the VSEWSS project from the Visual Studio solution then attempt your deployment again.
Problem Area: Event Receivers
Problem
You receive the error “Attempted to read or write protected memory.” when trying to cancel a checkout using the ItemCheckingOut Event Receiver.
Resolution
This is a known issue. To workaround you should set the Status property to SPEventReceiverStatus.CancelNoError instead of SPEventReceiverStatus.CancelWithError or setting properties.Cancel = true;
See http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver.itemcheckingout.aspx for more details.
Problem
You receive the error "The solution can not be deployed. Directory "ReturnOfSmartPart" associated with feature '2d7427c2-263d-45fe-acb3-4a0306093c04' in the solution is used by feature '28d3dcf2-409f-4653-8a69-1f0ce0819e1f' installed in the farm. All features must have unique directories to avoid overwriting files" when you try to deploy some web parts.
Resolution:
C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/BIN>stsa
dm.exe -o retractSolution -name ReturnOfSmartPart.wsp -allcontenturls -immediate
C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/BIN>stsa
dm.exe -o deleteSolution -name ReturnOfSmartPart.wsp
Problem
I reseive the following error: "The language-neutral solution package was not found", when use Depliy option to deploy my Web Part.
Resolution:
This error is caused by a caching issue in Visual Studio. Restart Visual Studio to address the problem.
Found on the following page:
http://www.microsoft.com/downloads/details.aspx?FamilyID=3E1DCCCD-1CCA-433A-BB4D-97B96BF7AB63&displaylang=en
You get this error when you try to publish an already published InfoPath form in SharePoint:
"A deployment or retraction is already under way for the solution ..."
If you go into the event log, you will notice different error messages related to this event. For example, one message will be as following:
EventType ulsexception12, P1 w3wp.exe, P2 6.0.3790.1830, P3 42435be1, P4 microsoft.office.infopath.server, P5 12.0.4518.0, P6 4541816a, P7 12961, P8 161, P9 nullreferenceexception, P10 8gec.
Another will look like the following:
An exception occurred during loading of business logic. (User: Server/Administrator, Form Name: Teachers, IP: , Request: http://Server/_layouts/Formserver.aspx?XsnLocation=http://server/FormServerTemplates/teachers.xsn, Type: FileNotFoundException, Exception Message: Could not load file or assembly 'file:///C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/Template/Features/FT-01-08f7ce0d-e5ba-7eab-8b14-ac2eb94f1add/Teachers.dll' or one of its dependencies. The system cannot find the file specified.)For more information, see Help and Support Center at
Now both these messages are misleading. The first one shows a "nullreferenceexception" and the other one mentions a missing file or dependency. Because of these messages I wasted time in trying to resolve the "nullreferenceexception" error but later it turned out that somehow the form didn't get published properly the first time we published it in SharePoint. Now when we were trying to republish the form but SharePoint was giving us errors. On each attempt SharePoint threw a new error message. One thing that I noticed was that the publishing process stopped the "Windows SharePoint Services Administration" service which was one of the reasons we were unable to republish the form. So check services and start this service if it's stopped and then run the following command:
stsadm -o execadmsvcjobs
If you try to publish the form without starting the "Windows SharePoint Services Administration" service, you will get the following error:
"The timer job for the operation has been created. However, it cannot be run because the administrative service for this server is not enabled."
So start the service and run the stsadm command. This will publish your form and hopefully, you will get rid of the error that said that there was a "nullreferenceexception" in your form. If you still get the same error (A deployment or retraction is already ...) then try running the following command to cancel the deployment that was started earlier:
stsadm –o canceldeployment –id
Timer Job ID can be copied from "Central Administration > Operations > Timer Job Definitions" page. See the most recently created job, you can also verify by looking at the title. Right click the "Job" link and copy the URL. Locate the "JobId" parameter in the URL, this parameter contains the ID.