SharePoint Development and Programming FAQ RRS feed

  • General discussion

  • Question 1:

    What resources are available for new SharePoint developers?


    SharePoint Developer Introduction for .NET Developers


    SharePoint 2007 Videos and Webcasts

    Microsoft SharePoint Team Blog

    Best Practices Resource Center for SharePoint 2007 (NEW)

    Arpan Shaw's Blog

    Paul Andrew's Blog

    SharePoint Practice and Guidance


    Question 2:

    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.



    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.


    Microsoft Office SharePoint Server 2007 SDK: Software Development Kit


    Windows SharePoint Services 3.0: Software Development Kit (SDK)


    Question 3:

    You receive “The "yourWebPartName" Web Part appears to be causing a problem” or "An unexpected error has occured"  or another generic error message when developing a web part.



    Exceptions are caught by SharePoint and a friendly error message is displayed instead of a stack trace.

    To display the full exception needed for debugging make the following changes to your SharePoint site’s web.config file (Inetpub\wwwroot\wss\VirtualDirectories\yoursite\web.config).


     Find:   <SafeMode CallStack="false" />

     Replace with: <SafeMode CallStack="true" />

     Find:   <customErrors mode="On" />

     Replace with: <customErrors mode="Off" />

     Find:   <compilation debug="false" />

     Replace with: <compilation debug="true" />


    Reproduce the problem and the true exception will be displayed.


    Question 4:

    You receive “Unknown Error” or another generic error message when developing aspx pages beneath _layouts.



    Application pages beneath _layouts have a separate web.config file that needs updated to enable more detailed error messages.


    Open \Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\web.config

    Add the following XML block immediately after the <configuration element.


        <SafeMode CallStack="true">





    Find:   <compilation debug="false" />

    Replace with: <compilation debug="true" />


    Question 5:

    You are developing a SharePoint component on an XP or Vista client and you need to debug to troubleshoot your component.



    Enable Visual Studio 2005 or 2008 Remote Debugging to enable remotely setting breakpoints and single step debugging through your code.


    See the following article for detailed configuration settings:


    Once the debugger is configured you will need to select Debug -> Attach to Process. You should see a list of processes appear. You will need to select w3wp.exe (there may be multiple instances and yes you can multi-select) and click “Attach”.


    Once attached you can set a break point in the code that you need to debug and reproduce the problem on the server.

    For web parts this could be refreshing the page

    For a feature receiver this could be activating or deactivating the feature

    For an event receiver this could be manipulating data in a list (such as adding, deleting, check-in/check-out) etc…

    Note if you are debugging across different domains try the following guidance:


    On your development workstation create a local account with the same name and password as your domain account then add it to the administrators group.


    On the remote server create a matching domain account (same username and password) and add it the administrators group.


    Configure the Visual Studio Remote Debugger Service on the remote server to login as the domain account.


    Question 6:

    You are trying to call a SharePoint web service but you are receiving SoapException or SoapServerException errors.



    Add a catch handler to your web service call and handle the exception. 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




    Question 7:

    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.



    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.


    Question 8:

    When using the SharePoint class UserProfileManager to read user profiles you receive the error “Only an administrator may enumerate through all user profiles”.



    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.

    Question 9:

    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.



    The web service needs credentials to be set before making calls.


    ·         listService.UseDefaultCredentials = true;  // use currently logged on user

    ·         listService.Credentials = new System.Net.NetworkCredential("user", "pass", "domain"); // use specified user


    Question 10:

    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.



    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. 


    Question 11:

    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.



    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)


    Question 12:

    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.”



    Remove all projects except the VSEWSS project from the Visual Studio solution then attempt your deployment again.


    Question 13:

    You receive the error “Attempted to read or write protected memory.” when trying to cancel a checkout using the ItemCheckingOut Event Receiver.



    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 for more details.

    Question 14:

    My webpart is essentially "frozen" or dead after I write a file to the client using Response.WriteFile or .End or .Flush etc..


    Question 15:

    You receive a 401 Access Denied when calling web services and you know permissions are configured correctly. 


    Thursday, June 12, 2008 6:07 PM