Tuesday, 31 May 2011

Flaw in SolutionContexts.GetEnumerator

I’m guessing that this post will be useful to a very small number of people if at all. However there might be a bigger lesson here for people writing their own collections and that is how not to code GetEnumerator method.

but first some background information.

when working with a visual studio add-in I needed find out weather a specific project is excluded from the build cycle.

the DTE provide interfaces and object to access this info and the code I ended up with looked like this:

   1: foreach (SolutionContext context in 
   2:    ApplicationObject.Solution.SolutionBuild.
   3:        ActiveConfiguration.SolutionContexts)
   4: {
   5:     if (context.ProjectName.Contains(project.Name))
   6:         return !context.ShouldBuild;
   7: }

However, this code resulted in an exception popping from time to time which took me a little while to understand.

the exception I got was :

System.ArgumentException
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
System.Collections.IEnumerator GetEnumerator()
at EnvDTE.SolutionContexts.GetEnumerator()

where the line number pointed to the foreach statement.

After some digging I found that this happens if in the solution you have an unloaded project as part of the solution. and the fix was quite simple jut replace the foreach with a simple for resulting in something like:

   1: var contexts = ApplicationObject.Solution.
   2:    SolutionBuild.ActiveConfiguration.
   3:    SolutionContexts;
   4:  
   5: for (int i = 0; i < contexts.Count; i++)
   6: {
   7:     try
   8:     {
   9:         var context = contexts.Item(i + 1);
  10:         if (context.ProjectName.Contains(project.Name))
  11:             return !context.ShouldBuild;
  12:     }
  13:     catch (ArgumentException)
  14:     {
  15:         //this is thrown when a project is unloaded
  16:     }
  17: }
  18: return false;

Now I can understand why an unloaded project will throw an exception if you try to access its configuration data. What I don’t understand is why they didn’t handle this inside the GetEnumerator and instead choose to crash it as well.

I think this is a mistake, in general if a piece of the information is missing don’t fail the entire operation just exclude that piece from the result. that way you will enable the user to decide what to do with the info he does have.

what do you think?

Thursday, 26 May 2011

Don’t you love useful error messages?

image




Ok now what?

Tuesday, 24 May 2011

Exporting Code Metrics from Command Line

A couple of months ago Microsoft released a tool enabling to gather code metrics on code form command line. (detailed post here).

While it took me some time I’ve updated my Msbuild custom tasks project and added an Msbuild task for better integration of the tool into a build cycle.

The task enable the exporting of metrics for a given solution and includes an xsl to transform the resulting xml into an html report.

(older tasks in the project allowed running all tests (using mstest) in a given solution and exporting VS coverage report to an xml)

To download the latest release go to here, and if you have any questions or additional requests contact me either through the CodePlex forums or directly.

Monday, 23 May 2011

Presenting at Sela’s Developers Days 2011

image

Towards the end of June I’ll be participating in Sela’s “Dev. Days” conference. Unlike other conference, “Dev Days” event is a collection of 1 full days workshops that will be given over the span of an entire week. During this week there will be 25 different workshops in various subject aiming at beginners and advanced Developers alike.

My part in this event will be 2 workshop that I’ll be having:

1. Introduction to Scrum

At this workshop ill be going over the principles of agile. I will show the basic Scrum process and technique and will demonstrate the key differences between Agile way of doing things and classical waterfall approaches.

If you are want to know what the agile buzz is all about I really recommend attending this day.

2. Introduction to Test-Driven Development

TDD has established itself as one of the leading practices in the Agile community. However there are several obstacles in actually starting to TDD. The goal of this day is to give all participant a good starting point for actually starting to code in the TDD style.

If you ever wanted to give TDD a go, but always found it hard to start. Maybe this day will get you going

2 other related workshop that might be of interest in the context of agile and testing are:

Team Foundation Server 2010 and Visual Studio 2010 and Visual Studio 2010 Testing Tools. but of course the week has many more very interesting workshops. for the full agenda go here and if you want to register follow this link.

Sunday, 22 May 2011

My Presentation at “QA and Development in Agile”

This is the presentation I gave last week over at the “QA and Development in Agile” conference (including some extra slides the I didn’t have the time to go over). Unlike other presentation this one was solely process related and not about any tool so I hope everyone enjoyed it.

The main pint o the talk was that its more important to optimize the team feature throughput than the team utilization and I hope I managed to get it across.

Scrum Project Management

Would you like hear me present? Contact me!

and in any case would love to get your feedback on the experience.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Walgreens Printable Coupons