SharePoint 4 Developers

Additional reference guide in .NET / SharePoint Development

Article published in the Codificando .Net e-Magazine

My article about the News in SharePoint 2010 Development was published.

Hi folks,

I would like to inform that in this Codificando .Net e-Magazine issue my article about the News in SharePoint 2010 Development was published! (in Portuguese language)

This article is very important because many of the things that I have already talked about Sandboxed Solutions and other SharePoint 2010 news are contained therein, and all the development news were listed and commented.

I consider this e-magazine very important because it provides excellent technical materials for the .Net community free of charge!

Thanks to Codificando .Net and all the editorial team for this opportunity!



Marcel Medina

Click here to read the same content in Portuguese.

Error occurred in deployment step 'Add Solution': Property 'SiteUrl' contains an invalid URL / The default web application could not be determined

Error occurred in deployment step 'Add Solution': Property 'SiteUrl' contains an invalid URL. Error occurred in deployment step 'Add Solution': The default web application could not be determined.

Hi folks,

These last days I faced an error in SharePoint 2010 while I was creating BDC Model projects. At the moment of deploying my solution I got this error message in the Beta version:

Error occurred in deployment step 'Add Solution': Property 'SiteUrl' contains an invalid URL. Import failed with the following exception message: The site <site> could not be found in the Web application SPWebApplication Name=<webapplication>.
Parameter name: properties

In the RTM version the error message changed a little bit, which is still not very clear:

Error occurred in deployment step 'Add Solution': The default web application could not be determined. Set the SiteUrl property in feature <feature> to the URL of the desired site and retry activation.
Parameter name: properties

In order to solve this issue, I searched at the Internet for similar issues and I found out an excellent article of Jan Tielens that explains a workaround for that.

Just because I don’t simply like to add links to other sites with specific solutions, due to broken links, I am going to let this available here in my blog.

Getting the error message

1 – Create a new solution with a project of type Business Data Connectivity Model according Figure 1:

Figure 1 – BDCModel Project

2 – Try to deploy by Visual Studio, the error message above will show up (depending on the version).

Correcting the problem

1 – Open the Feature XML file (Figure 1) and notice there is just only one property:

Figure 2 – Original XML File

2 – Add the following element to the XML, according Figure 2:

Code Snippet
  1. <Property Key="SiteUrl" Value="http://localhost/sites/portal"/>

Figure 3 – Updated XML File

Note: Change the SiteUrl value to your seu web site url.

3 – Deploy successfully!



Marcel Medina

Click here to read the same content in Portuguese.

SharePoint 2010 Developer Dashboard

Learn how to enable the Developer Dashboard, how to use the APIs to display its Tracing info and how to display the rendering results of your page graphically.

Hi folks,

When developing solutions, developers have the concern to deliver functional solutions that conform to the requested requirements. Although I always analyse the performance of my applications, most of the business solutions that I have worked performance is not a critical factor.

Depending on the scenario, what if performance is a requirement? How to get diagnostic information from your solutions in SharePoint 2010?

Precisely now there is the Developer Dashboard that brings a dashboard of tracing info.

In this article I will show how to enable the Developer Dashboard, how to use the APIs to display its Tracing info and how to display the rendering results of your page graphically.

Introducing the Developer Dashboard

Like something unknown, first of all I would like to introduce the Developer Dashboard, as we can see it below:

Figure 1 - SharePoint 2010 Dashboard Developer

Note: Note that the dashboard border is green, because neither asserts nor critical events are displayed. I'll talk about the color changes later in this post.

The left side shows the http handler events executed during the page rendering and their execution times, whilst in the right side a mix of comprehensive information and also details of the request can be found, such as the queries sent to database.

Interestingly, the links show the callstack of the message and other details, according to the figure below:

Figure 2 - Details of a database query

Once this is not unknown anymore for you, let's check what matters.

Enabling and disabling the Dashboard Developer

By default the Dashboard Developer is disabled and in order to display it there are three possibilities:

  • .Net code


  • PowerShell

There are also three display levels of the Dashboard. As described below:

  • "On" - the dashboard will always be displayed;

  • "Off" - disables the dashboard;

  • "OnDemand" - adds an icon to the page, which allows the visualization of the dashboard only when clicked (toggling between On and Off).

The figure below displays this icon:

Figure 3 - Developer Dashboard Icon

NOTE: It is important to note that when the Dashboard is enabled using OnDemand, only Administrators and Site Collection Owners have access to it. Members and visitors will not see the icon. In this post the Developer Dashboard will be displayed using the display level "OnDemand", which in my point of view is the ideal.

.Net Code

A Feature that enables or disables the dashboard can be created, instead of using scripts for that. This way the activation or deactivation can be done directly through the Site Collection Features page.

Create a project in Visual Studio 2010 of Empty SharePoint Project called DeveloperDashboard. Choose the option of a Farm Solution. Your initial project should look like this:

Figure 4 – DeveloperDashboard Feature (Initial Project)

Add an Event Receiver to the Feature according the figure 5:

Figure 5 – Adding an Event Receiver

The class DeveloperDashboardEventReceiver will be created automatically, with all the methods commented out. Add the following code for the Feature Activation and Deactivation:

Code Snippet
  1. public override void FeatureActivated(SPFeatureReceiverProperties properties)
  2. {
  3.     SPWebService contentService = SPWebService.ContentService;
  4.     contentService.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.OnDemand;
  5.     contentService.DeveloperDashboardSettings.Provision();
  6. }
  8. public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
  9. {
  10.     SPWebService contentService = SPWebService.ContentService;
  11.     contentService.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.Off;
  12.     contentService.DeveloperDashboardSettings.Unprovision();
  13. }

In the end your project should look like the figure below:

Figure 6 – DeveloperDashboard Feature (Final Project)

Compile and deploy the project directly from the Visual Studio 2010 in development environments. For production environments deploy it via STSADM according the figure below:

Figure 7 - Deploy of the feature on Production

In the end this feature must be enabled as the following figure:

Figure 8 - Deploy of the Feature "Developer Dashboard"

Download the solution here.


Open the Command console and enter the following cmdlet to enable the Developer Dashboard:

stsadm –o setproperty –pn developer-dashboard –pv OnDemand

To disable it:

stsadm –o setproperty –pn developer-dashboard –pv Off

NOTE: The option-pv is case-sensitive.


Figure 9 - Execution of commands via STSADM


Another possibility is to use PowerShell for running scripts.

To enable the Developer Dashboard:

$dash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$settings = $dash.DeveloperDashboardSettings
$settings.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand


Figure 10 - Script activation via PowerShell

To disable it:

$dash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$settings = $dash.DeveloperDashboardSettings
$settings.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::Off


Figure 11 - Script deactivation via PowerShell

Measuring performance and adding messages via Tracing

Once the Developer Dashboard is active, we can proceed with the addition of Tracing messages in SharePoint 2010.

As already said this is an excellent way to measure the performance of code and add custom messages for tracking.

In order to measure the time of the code snippet that we intend to track, the class SPMonitoredScope should be used. This information will be available on the left side of the Dashboard.

In order to add log messages, warnings or assert messages, the class SPCriticalTraceCounter should be used. This information will be available on the right side of the dashboard, and a link will be available to visualize the message details.

NOTE: The callstack, which is in the message details, can add a few Kb on the page. Thus track the growth of the amount of custom messages that you have, they will increase the size (Kb) of your page if the Developer Dashboard is enabled.

Add a new project of Visual Web Part called Tracing. The solution should resemble the figure below:

Figure 12 - Web Part Tracing Project

Add the code below in the file TracingWebPartUserControl.ascx.cs:

Code Snippet
  1. using System;
  2. using System.Web.UI;
  3. using System.Web.UI.WebControls;
  4. using System.Web.UI.WebControls.WebParts;
  5. using Microsoft.SharePoint.Utilities;
  7. namespace Tracing.TracingWebPart
  8. {
  9.     public partial class TracingWebPartUserControl : UserControl
  10.     {
  11.         protected void Page_Load(object sender, EventArgs e)
  12.         {
  13.             // Using class for tracking the execution time
  14.             using (SPMonitoredScope sc = new SPMonitoredScope("LoadMeter"))
  15.             {
  16.                 for (uint i = 0; i < 10; i++)
  17.                 {
  18.                     // Adding custom messages
  19.                     SPCriticalTraceCounter.AddDataToScope(i, "Loop For", 15, string.Format("Mensagem monitorada - {0}", i.ToString()));
  20.                 }
  21.             }
  22.         }
  23.     }
  24. }

Class TracingWebPartUserControl

This code contains two classes SPMonitoredScope and SPCriticalTraceCounter as already commented. It is important to know that the TraceLevel (3rd parameter of the method AddDataToScope) can be:

  • 1 – Critical
  • 4 - Exception (Watson)
  • 6 – Assert
  • 8 – Warning
  • 10 – Unexpected
  • 15 - Monitorable

Perform the addition of the Web Part (1), save it (2) and then visualize the Developer Dashboard (3) as shown below:

Figure 13 - Adding Web Part Tracing

Check out the Developer Dashboard, its border color is no longer green color as displayed in Figure 1. Differently it is in red color, which shows that asserts and critical events occurred (in this case the messages created):

Figure 14 - Time Scope and custom messages added

Click over one of the messages and note that the message details and callstack can be seen:

Figure 15 - custom message displayed in details

Download the solution here.

Developer Dashboard Visualizer

We can improve the Dashboard with a graphic display called Developer Dashboard Visualizer, which was created by Jaap Vossers and consists of a UserControl that makes use of JQuery to view the axis Events x Execution time (left side of the Developer Dashboard).

This project is available on Codeplex:

Download the wsp package and install it using the STSADM, as shown below:

Figure 16 - Enabling the Developer Dashboard Visualizer

The http handler events are displayed immediately above the dashboard:

Figure 17 - Graphical View

In this article we checked how to enable the SharePoint 2010 Developer Dashboard. We have checked that diagnostic information and tracing messages are output on the page to the browser that made the request. Such information may help to clarify errors or undesired results during the processing of your solution in SharePoint 2010.

I hope these tips are helpful.



Marcel Medina

Click here to read the same content in Portuguese.