Run SPDisposeCheck as part of your build process

As mentioned before, I’ve been automating the building and analysis of our SharePoint code, and this led me to ask, can you run SPDisposeCheck as part of a TFS build process?

Yes we can. Richard Fennell has a concise and simple description of how to do it. It’s best to read that, but in case that site goes down, the short of it is – use InvokeProcess to run SPDisposeCheck, and it’ll return a value that is the number of errors/warnings it finds. I find that that’s enough to choose whether to write a warning to the output of the build, and I don’t then parse and write the individual warnings into the build. These should be captured by the build log, and they’re pretty obvious, so it doesn’t seem worth the hassle. You could do it if you really wanted to.

Don’t forget you can use attributes to prevent false positives – though I still have issues with anonymous delegates that are false positives (how do you add the attributes?), and that’s what’s causing the two warnings above.

Run SPDisposeCheck as part of your build process

Practical SPDisposeCheck – Namespaces, Delegates and RootWebs

SPDisposeCheck is a great utility for checking the disposal patterns you’re using in your SharePoint solution. Believe me, even experienced practitioners make mistakes; object disposal in SharePoint is hard.

Now, every time someone says that SPDisposeCheck is great, someone posts back that it isn’t perfect. They’re right; it won’t pick up every invalid disposal pattern – but it’s pretty good. Given the choice of it or no check, it’s a clear winner.

I’m not going to describe it much – there are good articles already out there about the problem, and how to use SPDisposeCheck. It’s also well worth installing the latest version, which integrates with Visual Studio. That’s brilliant – you can run a test over your assemblies with each build.

However, recently I took over someone else’s code; SPDisposeCheck proved invaluable, but quirky too. This post will examine some of the practical issues that I found with using it.

Continue reading “Practical SPDisposeCheck – Namespaces, Delegates and RootWebs”

Practical SPDisposeCheck – Namespaces, Delegates and RootWebs