SPRequest ULS Entries

The SharePoint ULS logs always report objects not being explicitly disposed of, even for some of the SharePoint object model calls, although these are supposedly false positives.

Now, not all entries that are flagged will be issues, but initially there’s no apparent easy way of determining if the object is indeed causing a memory leak.

A sample log entry will look like:

An SPRequest object was reclaimed by the garbage collector instead of being explicitly freed. To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it. Allocation Id: {FDE3179D-E9C7-476B-9E60-ED68C55827ED} To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService. CollectSPRequestAllocationCallStacks = true.

The last line of this entry indicates a way of getting more useful information to allow you to diagnose the problem and determine if it requires fixing.
Continue reading

Posted in SharePoint | Tagged , , | Leave a comment

Get CAS IPermission for exception

If you’re working on a SharePoint solution that requires a custom code access security (CAS) policy, the following is an easy way of determining the permission(s) you need to add to the config.

For this to work, you need to be able to debug the code, which should be a given, considering you’re creating a custom CAS for a solution you’re writing . 🙂

A basic CAS will look something like:

<CodeAccessSecurity>
  <PolicyItem>
    <PermissionSet class="NamedPermissionSet" version="1">
      <IPermission class="SecurityPermission" version="1" Flags="Execution" />
      <IPermission class="AspNetHostingPermission" version="1" Level="Minimal" />
      <IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" ObjectModel="True" />
    </PermissionSet>
    <Assemblies>
      <Assembly Name="$SharePoint.Project.AssemblyName$" Version="$SharePoint.Project.AssemblyVersion$" PublicKeyBlob="$SharePoint.Project.AssemblyPublicKeyBlob$"/>
    </Assemblies>
  </PolicyItem>
</CodeAccessSecurity>

Continue reading

Posted in Security, SharePoint | Tagged , | Leave a comment

Dynamically load JavaScript file

Sometimes you don’t always want a JavaScript file to load. If, for instance, a control that utilises it is loaded by a page that already references the same JavaScript file, you wouldn’t want to load the script file again.

Note: This being a SharePoint blog, the script shown here is tailored for that platform but will quite easily port to other non SharePoint sites.

A good example of this would be a custom SharePoint WebPart that uses jQuery. Now, say you don’t have control over the page that will host the WebPart and therefore can’t guarantee that the jQuery script will be present in the page\master page\delegate header control. You could dynamically load the script file as the WebPart loads. The problem with this is that the rendering page might already be loading the same script.

Also, by loading the jQuery script file, especially in an environment you have little control over (maybe a WebPart you developed, which is used by many different systems and configurations) you could potentially cause a conflict on the use of the $ alias, which jQuery creates by default.
Continue reading

Posted in JavaScript | Tagged , | Leave a comment

Validation of viewstate MAC failed in AddWrkfl

I recently added a delegate control to a SharePoint solution. The delegate control was used to dynamically insert a custom user control into the master page. Part of the functionality of this control required the use of hidden fields.

Everything worked perfectly until I tried to add or update a workflow against a list. After clicking Next on the add workflow page, the following error was thrown:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster
Continue reading

Posted in SharePoint, Workflow | Tagged , , | Leave a comment