SharePoint 4 Developers

Additional reference guide in .NET / SharePoint Development

Error occurred in deployment step 'Add Solution': Failed to load receiver assembly

Some issues in the integration of Visual Studio 2010 x SharePoint Foundation 2010 still can be found: Error occurred in deployment step 'Add Solution': Failed to load receiver assembly Microsoft.Office.SharePoint.ClientExtensions or Could not load file or assembly Microsoft.Office.Server

Hi folks,

The integration Visual Studio 2010 x SharePoint Foundation 2010 when deploying BDC Model Solutions still presents some issues. The problem occurs in Visual Studio because it cannot find the required DLLs to perform the operation. The error messages are listed below:

Problems:

Error occurred in deployment step 'Add Solution': Failed to load receiver assembly "Microsoft.Office.SharePoint.ClientExtensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" for feature "<Sua Feature>: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Office.SharePoint.ClientExtensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Office.SharePoint.ClientExtensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

Error occurred in deployment step 'Add Solution': Could not load file or assembly 'Microsoft.Office.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

Solution:

In order to cross off this problem, some files of SharePoint Server 2010 need to be copied, which can be found in the directory 14\ISAPI:

  • microsoft.office.sharepoint.clientextensions.dll
  • Microsoft.Office.Sharepoint.ClientExtensions.xml
  • Microsoft.Office.Server.dll
  • Microsoft.Office.Server.xml

Register the DLLs in the GAC to fix it, just copying them to the directory C:\Windows\assembly.

Reopen the Visual Studio 2010 and deploy your BDC Model Solution successfully!

Cheers,

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:

1D806A05AA43783B_453_0[1]
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:

1D806A05AA43783B_453_1[1]
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

  • STSADM

  • 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:

1D806A05AA43783B_453_2[1]
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:

1D806A05AA43783B_453_3[1]
Figure 4 – DeveloperDashboard Feature (Initial Project)

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

1D806A05AA43783B_453_4[1]
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. }
  7.  
  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:

1D806A05AA43783B_453_5[1]
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:

1D806A05AA43783B_453_6[1]
Figure 7 - Deploy of the feature on Production

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

1D806A05AA43783B_453_7[1]
Figure 8 - Deploy of the Feature "Developer Dashboard"

Download the solution here.

STSADM

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.

Result:

1D806A05AA43783B_453_8[1]
Figure 9 - Execution of commands via STSADM


PowerShell

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
$settings.Update()

Result:

1D806A05AA43783B_453_9[1]
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
$settings.Update()

Result:

1D806A05AA43783B_453_10[1]
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:

1D806A05AA43783B_453_11[1]
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;
  6.  
  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:

1D806A05AA43783B_453_12[1]
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):

1D806A05AA43783B_453_13[1]
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:

1D806A05AA43783B_453_14[1]
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: http://devdashvis.codeplex.com/

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

1D806A05AA43783B_453_15[1]
Figure 16 - Enabling the Developer Dashboard Visualizer

The http handler events are displayed immediately above the dashboard:

1D806A05AA43783B_453_16[1]
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.

References:
http://blogs.msdn.com/pandrew/archive/2010/03/26/sharepoint-2010-developer-dashboard-for-debugging-code.aspx
http://weblogs.asp.net/jcortez/archive/2010/03/16/developer-dashboard-in-sharepoint-2010.aspx
http://devdashvis.codeplex.com/

Cheers,

Marcel Medina

Click here to read the same content in Portuguese.