Archive for the ‘developing’ Category

Beware of the SharePoint Memory Leaks!

Wednesday, March 12th, 2008

Beware of the SharePoint Memory Leaks!

You might not know it, but when developing for SharePoint (either WSS 3.0 or MOSS 2007) it is very easy to cause memory leaks, which can ultimately thrash your SharePoint server’s performance. The reason for this is that even though your own code might be written using only managed code, the SharePoint API still uses unmanaged code in some places. These unmanaged resources have to be explicitly disposed of, especially considering the fact they are living inside an ASP.Net web application (SharePoint) and potentially can have a long lifetime.

The problem is that the SharePoint API doesn’t always make clear when exactly you have to dispose of objects explicitly. Sometimes it may look like you’re just inspecting a value of a property, while in the background a whole new object is instantiated, which holds valuable unmanaged resources that should be freed by the caller (you!). Other times you might find yourself disposing an object, only to find out you weren’t supposed to…

Way back in June 2006 Microsoft employees Scott Harris and Mike Ammerlaan released their article Best Practices: Using Disposable Windows SharePoint Services Objects on MSDN, which can be regarded as the mother of all articles on this subject. I think this article is often overlooked and should be considered essential reading material for every serious SharePoint developer out there. Also read their more recent article called Best Practices: Common Coding Issues When Using the SharePoint Object Model, which also handles topics like data and object caching and writing scalable code.

Recently two other Microsoft employees also wrote interesting pieces on this subject. Stefan Goßner did a piece called Dealing with Memory Pressure problems in MOSS/WSS, in which he explains what a "Memory Pressure Situation" is and he lists some common causes and solutions for it. The other interesting read came from Roger Lamb. His entry is called SharePoint 2007 and WSS 3.0 Dispose Patterns by Example and in it he shows some very clear code samples and patterns on how to properly handle SharePoint objects.

Very cool material, guys!

Return of SmartPart V1.3 released

Friday, February 15th, 2008

Yesterday Jan Tielens released a new version of his famous SmartPart to the community. It is now at version 1.3 and here’s the changelog:

  • Added a setup wizard to install the Return of SmartPart.
  • Added sample user controls (including connectable user controls and AJAX user controls).
  • Added localization support for ASP.NET AJAX user controls.
  • Various minor bug fixes.
  • Nice 2-minute screencast on how to deploy and test the SmartPart.
  • 64 bit version available.

Great work, Jan! I also like the fact you’ve used Lars Fastrup’s SharePoint Solution Installer for deploying SmartPart.

Free e-book: The Developer Highway Code

Saturday, February 9th, 2008

Today I stumpled upon my TechEd 2007 goodie bag and found a little card I had picked up somewhere at the event. The card advertised a free prize draw (twenty copies of Vista Ultimate). All you had to do was download The Developer Highway Code, whatever that might be.

The Developer Highway Code Cover ImageOfcourse being Dutch means I’m always in for a free prize draw, so I immediately visited the URL printed on the card. It turned out The Developer Highway Code is a cool free e-book released by Microsoft (available in PDF and XPS format). It seems to have been around since 2006, but I hadn’t heard of it before. The book was written by Microsoft UK employee Paul Maher and Alex Mackman and has been revised in 2007 (probably right before TechEd). Here’s the official description, which you can find on the book’s website:

"To build software that meets your security objectives, you must integrate security activities into your software development lifecycle. This handbook captures and summarises the key security engineering activities that should be an integral part of your software development processes.

These security engineering activities have been developed by Microsoft patterns & practices to build on, refine and extend core lifecycle activities with a set of security-specific activities. These include identifying security objectives, applying design guidelines for security, threat modelling, security architecture and design reviews, security code reviews and security deployment reviews."

Unfortunately the free prize draw seems to be over, but the e-book is still available. I suggest every Microsoft developer to take a look at it, since it’s a very good summary of many things a developer should look at when developing secure applications.

Blurry WPF editor in Visual Studio 2008

Friday, February 8th, 2008

A short post this time…

Ever wondered why Visual Studio 2008’s WPF editor shows up kinda blurry on your CRT monitor? It turns out it’s a WPF control itself (as you had probably already guessed). But did you know that this also means it makes use of ClearType, even if you haven’t got an LCD monitor hooked up? Read all about it at Todd Mancini’s blog.

Visual Studio 2008 and SQL Server 2005 Business Intelligence Development Studio

Wednesday, December 19th, 2007

As soon as Visual Studio 2008 went RTM I installed it and removed Visual Studio 2005 from my system. As you might know VS2008’s new multi-targeting feature can target .NET Framework 2.0, 3.0 and 3.5 and should be fully backwards compatible with VS2005, so in theory there shouldn’t be any need for keeping VS2005 around*.

However, today I encountered an unexpected situation where I did need VS2005. I tried to launch the SQL Server 2005 Business Intelligence Studio, which failed miserably… As you may know Business Intelligence Studio makes use of the VS2005 IDE (it uses either an existing “normal” Visual Studio installation or it installs the Visual Studio Premier Partner Edition). I knew this, but I had expected it to somehow automatically (or magically :-)) switch to the VS2008 IDE, which ofcourse it did not.

Unwilling to re-install SQL Server 2005 I searched the internet for a solution to this problem and stumbled on a thread on the MSDN forums discussing this exact same issue. It contains an interesting reply by Microsoft employee Dan Jones. There he explains a way to install the VS2005 files need without the need for re-installing SQL Server 2005. Here’s the trick:

  1. Go to the location for SQL Server setup and run .\Tools\Setup\vs_setup.exe. This will install the VS Shell.
  2. Repair the Business Intelligence Studio installation by running the following command from the command line from the .\Tools directory (note: this should be typed on one line):
    start /wait setup.exe /qb REINSTALL=SQL_WarehouseDevWorkbench
    REINSTALLMODE=OMUS

I hope this helps some of you facing this same issue.

* In practice I recommend you still keep VS2005 installed, especially when doing team development. If you open a VS2005 solution in VS2008, it will ask you to convert existing solution files to the new VS2008 format. Once converted, these updated solution files cannot be used in VS2005 anymore.I actually asked Scott Guthrie a question about this on his blog and even got a reply from him. Here’s what he had to say (for the original reply search the comments on this blog posting):

Hi Leon,

> Hey Scott, I noticed VS2008 wants to
> convert my existing VS2005 solutions.
> Why? The problem is that the converted
> solutions cannot be opened in VS2005 anymore,
> which some of my team members still use. I
> thought VS2008’s multi-targeting support didn’t
> require me to have VS2005 installed anymore,
> but now I still have to install them side-by-side.

VS 2008 allows you to target .NET 2.0 projects, but does make some changes to your solution file (that prevents it from being opened with VS 2005). What you can do, though, is maintain two solution files that point to the same projects and have them work with both VS 2005 and VS 2008.

Here are some blog posts that cover this more:

www.west-wind.com/…/122975.aspx

stevenharman.net/…/multi-targeting-vs2005-and-vs2008-web-application-projects-a-gotcha.aspx

codebetter.com/…/enabling-team-development-with-vs2008-2005-mix.aspx

Hope this helps,

Scott

Yeah Scott, it did!