Wednesday, 30 July 2008

.NET 3.5 Microsoft Courseware with IEEE Computer Society

I logged on to the IEEE Computer Society site for the first time in a few months today and got a pleasant surprise when I saw that at least some of the latest .NET 3.5 courseware is available free (usually £210.33 last time I looked) to members. It even includes courses on the ADO.NET Data Services and the Entity Framework.

I've done a few of the course they provide before including the Certified Ethical Hacker course, and a bunch of .NET ones. The only downside with the .NET ones is that (at least last time I did one) you don't get the virtual labs, you do get the exercises though so you can setup your own machine and work through them anyway. There are bucket loads of courses available to memebers on .NET, Java, Databases (SQL Server 2000, 2005 and Oracle 8 and 9i), Cisco, Adobe, business skills, IT Security, SharePoint (WSS and MOSS) and lots, lots more.


So if you're not an IEEE Computer Society member and you're thinking of doing any self-paced at home IT courses then I'd recommend joining because for the cost of buying one of these courses from Microsoft you can have a years membership, a great magazine (Computer) every month, and lots and lots of free courses!

Oh and well done to Microsoft for supporting IEEE Computer Society members in this way.

Monday, 28 July 2008

Resharper 4 Bug with 'Use Format String'

I'd like to say first that I really, really like Resharper 4.0 and have made it my mission to persuade my boss to buy it for all of the Dev's where I work. I got my copy free at a NxtGenUG Southampton meeting and it continues to make my life as a developer easier.

But...

I've come across a small bug in Resharper 4.0 today, so I thought that I'd share so that others become aware.

Real code has been changed to protect the innocent (and because it belongs to my employer).

Start off with a StringBuilder.Append statement that uses the '+' operator to concatenate a string with an object. Why an object, well because that's what the code I'm working with has, not ideal, but that's working with legacy code for you sometimes.

Of course, using the Append statement with string concatenation isn't ideal practice either and what I'd like is to change it to an AppendFormat call. Now Resharper makes this very, very (seductively) simple.

Here's my example code before I let Resharper do its' thing:

Here's Resharper offering to do its' thing:


Here's the code that results:

The important line to note is that we now have:

stringBuilder.AppendFormat("{0} likes Resharper.", (object[])canBeCastToString);

Note the unnecessary cast to an object array. Because of this we now get the error:

System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Object[]'.

The solution is just to get rid of the superfluous cast to Object[].

I still really, really like Resharper 4.0.

Saturday, 19 July 2008

You Grok What You Eat

Following on from conversations that I've had with various people recently it has struck me, and its' not a revolutionary thought, that my practice, and my thinking about my practice, is intimately linked to the feeds I subscribe to, the books I read, the events I attend, the people I chat with, and my work. So, as I finally got around to adding my ALT.NET Geek Code, I thought I'd write a short blog focusing on the feeds I subscribe to and some of the more influential (on me that is) books I have read in the last couple of years.

With feeds I of course subscribe to those of friends (see right) and I won't list them again as they are always present on this site. I'll start by giving a special mention to my two favourite blogs.

Ayende @ Rahein's blog has to be top of my list, his blog is a pure goldmine of ideas and inspiration and I'd thoroughly recommend his Hibernating Rhinos series if you haven't seen it.

Next up, Scott Gu, always interesting to see what MS is coming out with next.

After these two, here's the rest:

For books the list is a lot shorter.

First up comes Object Thinking. I just loved this book and will happily rave about it to anyone. Having originally read Social Anthropology at university and then gone on to do a masters in social science research methodologies reading this book brought together for me a number of thoughts that had been swirling around in my mind about the potential importance of insights from Anthropology, Sociology and other social sciences that are rarely given any attention in computing. In fact when I read it, I read it as much as a anthropology of the practice of software development as a book that gives great concrete guidance on the practice of software development. It wasn't until going to a great talk by Alan Dean at the Southampton NxtGen that I realised I had probably missed a lot of what the author was actually trying to communicate. I fully intend to reread it before too long in the light of Alan's talk.

Next is 'Domain Driven Design' by Eric Evans. A fantastic book that has really changed the way that I try to design and code software. Putting it here is almost as much of a cliche as citing Scott Gu's blog but to ignore it would be to not mention an important part of my diet. I actually came to read it as it had been used so much as a counterpoint in Object Thinking's sometimes quite duological arguments.

Agile Project Management with Scrum by Ken Schweber. The first scrum book that I read. Easy to read, every page is worthwhile.

C# In Depth by John Skeet. I haven't quite finished this yet but I'm going to give it a mention anyway because already it is the best 'code' book I've read to date. A lot of coding books that I've got and read have really frustrated me because they all seem to cover the same old, same old ground every time. Jon's book is focused on C# and avoids being drawn in to the framework which is fantastic because the last thing that I'd have wanted is another book with another chapter on ADO.NET, ASP.NET, databinding, etc... I saw Jon give a talk on C# a while ago and for me it was the best technical talk I have ever attended. He involved the audience and I left feeling that I had really learnt something. This book is almost as good as his talks.

If C# in Depth was a book that I hadn't finished reading then the next book is a book that the authors haven't finished writing! 'Brownfield Application Development in .NET' by Kyle Baley and Donald Belcham is, so far, great and represents everything that I am trying to achieve in my job at the moment. I can't wait for the later chapters to be released and would recommend it to anyone who has to transform not just a poorly designed and coded piece of software, but the practices and patterns of a team also.

Other books worth a mention include the GoF Design Patterns, CLR via C#, Object Oriented Software Construction, The Knowledge Creating Company, The Object Primer, Being Digital (now that's going back some).

So where does this diet lead me? See the ALT.NET geek code on the right.

Thursday, 19 June 2008

Resharper 4.0 and Lambda Expressions

Now I'm fairly new to the wonderful world of Resharper, so barely a day goes by where I don't discover something new about it, or through it. But today I found a feature that just made me want to share about it straight away.

Let me set the scene.

I'm coding a Lambda expression for use as a predicate and when finished I notice the now familiar little light bulb. Hmmm I thought, now what could Resharper be wanting to tell me about my code?

Resharper offers conversion from Lambda to statement, and to anonymous method.(real code replaced throughout to protect the innocent)

That's right Resharper is offering to convert my Lambda to either an anonymous method or a statement! So let's see what it does to the code if I choose these options.

Well If I choose the option 'Lambda expression to statement it turns my code into this:

The same code as inline statement.Note with this option I am given the choice to now convert on to an expression, or to an anonymous method.

If I choose the option 'To anonymous method' my code looks like this:

The same code as anonymous method. Note that it is offering to convert my code back to a lambda

If I choose the 'Lambda expression to anonymous method' option and place the caret in to the delegate keyword then I get a different option however.

Different Resharper options with the anonymous method.

This time the options include one to convert my anonymous method to a named method. Choosing this does what you will no doubt expect. It creates named method.

private static bool NewPredicate(Person p)
{ return p.Name == "Sue"; }

and changes my code to read:

Person sue = people.Find(NewPredicate);

Actually I added the prefix new, as Resharper just put Predicate, but you get the idea. Of course, Resharper now gives me the option to inline my Predicate as either an anonymous method, or as a Lambda.

Resharper offering to inline my named delegate method.

Neat huh!

Choosing to inline as an anonymous method acts as I would expect, and puts the code back to be the same as the anonymous version above. Choosing to inline as a Lambda however a have a tiny, tiny gripe with.

Resharper offering to remove the 'redundant parenthesis' that it inserted.

As you can see above, Resharper has placed the target variable within brackets. Still, at least Resharper knows that it shouldn't have done this, as it offers to remove them!

What I really, really like most about this, and made me want to blog about it, it that it very neatly highlights some of the evolution of C# from version 1 with its' named delegates (though of course we didn't have delegate comparisons then), through version 2, with its' anonymous methods, through to the current version 3 with its' Lambda goodness.

Thursday, 12 June 2008

NxtGenUG Fest '08

Just got back from an excellent day attending the NxtGenUG Fest '08 at Microsoft's campus at Reading.

Like all NxtGen related events everything was smooth and incredibly well put together. I enjoyed all of the talks and some of them have definitely inspired me to go and hit the computer for a play.

Mike Taulty's talk on ADO.NET Data Services was an excellent and engaging introduction to this feature that will be properly released with the forthcoming .NET 3.5 Service Pack 1. The technology seems very seductive, and I will try and find some time before long to have a play with it but it seems very data driven to me and the implications of this if the technology was to be deployed much beyond a simple demo app concerns me a little. Still, until I look into it properly that's just a gut reaction and may well be wrong.

Daniel Moth gave a short talk on Parallel Linq which looked very interesting and this is something that I will definitely be looking into before long.

Dave Morrow gave a really interesting talk on providing BI using SQL Analysis Services, Proclarity, MS Performance Point and SharePoint (WSS 3). The world of BI (business information) is not one that I know particularly, but this talk has really gotten me wanting to have a play with these tools. It'll stretch the limits of my hardware (even with VMs) to get the necessary environments setup to play around sensibly with this stuff but I think that I'll enjoy it and it'll be worth it. One thing that I wondered watching this demo was whether I could bring SPSS (a statistical analysis package I used during my MSc) to the party and get some even more interesting information out of this mix. No doubt I'll blog about this when I've looked into it, and had a good play, some.

The talk that most interested me however was Oliver Strum's talk on F#. I can't overstate how interesting and well delivered this presentation was in my opinion. I'd been wanting to look into F# for a few months now without ever getting around to it. Oliver's talk has made this (along with my continued playing with Spec#) the new big priority for my personal R&D time. I'd heard/read that F# would be a good tool for writing business rules engines, but had been leaning toward doing this with a Boo based DSL. This introduction to F# is making me think that I really need to look into this before I make that decision. I suspect also that, as an added benefit, a play in this space will do wonders for my use of Lambda expressions in C# too.

Of course the day was not just about the great speakers (they were all great, not just the ones that I've highlighted), but like any NxtGen event it was also about the pizza, the swag. I got, amongst other things, a free copy of the full DevExpress software (no that's not why I'm so full of praise for Olivers' fantastic talk), and some Microsoft 'Heroes' chocolates. Beyond all of that though the chance to meet and chat with former colleagues (great to see such a large number from Immediacy) and other NxtGeners (great to see so many from the Southampton branch) really made the day. Congratulations and thanks to Dave, Rich and John for another brilliantly hosted and put together event.

Now I just can't wait for DDD 7 (which, incidentally, I have just submitted a proposal for a Grok talk on Design by Contract and Spec# for).

Saturday, 7 June 2008

Revisited: Insufficient Permissions on web.config when delegating administration of a web site to remote users in IIS 7

I have been meaning to return to this since I first posted on it and gave my talk about the remote management of IIS 7 at NxtGenUG Southampton. Well I've finally gotten around to it.

This error occurred when remote administration of an IIS 7 web site and/or application is delegated to an IIS 7 user, and that user attempts to alter a setting of the site/application from a remote machine. The solution that I originally posted was to grant the local Service account modify permissions on the web.config file in question. This always seemed unsatisfactory to me as it quite a sweeping grant that increases the surface area for security issues, breaking with the principal of least privilege as it does. However at the time I first looked into this it was already gone midnight and I had a big day the next day with work, a long drive, and then the talk to give, so I went to bed and decided to look into this again another day.

If you just want the solution then skip now to the bottom paragraph, if like me you believe that the journey is worth more than the destination (and if you've been struggling with this under pressure then I doubt you will) then here is also how I got there.

I finally got around to looking into this further last night (another post-midnight session). I ran procmon.exe (part of the Sysinternals suite) and replicated the issue on a new VM so that I could see what was going on 'under the hood'.

Image showing that the wmsvc process was impersonating the NT AUTHORITY\LOCAL SERVCE account when its' access was denied.

As the image above shows the wmsvc process was impersonating the NT AUTHORITY\LOCAL SERVICE account when it was denied access the web.config file of the site. So it would seem that in giving this account permissions on the web.config file I did the correct thing (I didn't so keep reading).

Something about all of this still puzzled me however, when I look at those events logged in procmon that show the wmsvc process accessing (successfully) the applicationHost.exe process it too is impersonating the NT AUTHORITY\LOCAL SERVICE account. Well you might think that makes sense, wmsvc is after all a service and that is the account that it is impersonating. The strange thing for me was this.

Image showing that applicationHost.config does not hanve any ACL entries for the NETWORK SERVICE account, but does have an entry for 'WMSvc'.

Looking at this what stands out to me are these two things. 1, there is no entry for NT AUTHORITY/LOCAL SERVICE. 2, there is an entry for something called WMSvc.

After a bit of Googling and reading around I have sussed what is going on, and why I couldn't work it out that evening.

With Windows Vista (and so of course Windows Server 2008) Microsoft looked to address the security risks that having services all running as the LOCAL SERVICE account poses. When I set the permissions on the web.config file to allow LOCAL SERVICE I am not just permitting the service that I am interested in (wmsvc) I am permitting any service that impersonates this user. This is after all what bothered me in the first place. Microsoft have introduced a feature termed Service Hardening that addresses this issue. What this means is that I can now give permissions that target a specific service only. Wow, that's a great (and necessary) improvement.

So the solution to the problem is this: give modify permissions to NT SERVICE\WMSvc. Do this and the remote delegated access will work like a dream, and the principal of least privelege will have been adhered to!

My only criticism of the new features in all of this is: why can't IIS Management do this setting of permission for me when I choose to delegate permissions to an IIS User for the management of a site or application? It would be a lot easier!

Friday, 6 June 2008

Team Foundation Server (TFS) 2008 Licensing Change

I'm looking into the licensing for TFS 2008 for my employers as my team are looking to migrate from VSS to TFS (hooray) and I have been asked to take the lead in this work. With TFS 2005 anyone who was going to raise issues (bugs, requests, and the like) in TFS, even if using the TeamPlain web client, had to have a valid CAL. This was a bit of an expensive pain and meant that at my last company (at least when I left) Gemini continued to be used by the Support team to raise and manage bugs, until someone (a ScrumMaster I think) moved them into an appropriate TFS project as a part of the project backlog.

Well with TFS 2008 this situation has changed. CALs are no longer required to raise bugs, add stories, and that sort of thing! This is fantastic news in my opinion as it should help encourage companies to move more wholeheartedly (and more fully) to TFS, a product which I really rate!

I can't wait to get it installed and get the new Conchango Scrum for TFS 2008 addin installed.

Check this blog for more on TFS 2008 licensing.