Archive for the 'General .NET' Category

Vista Launch Presentations

The presentations from my Vista Community Launch talk (21 Jan 2007) at the Manchester VBUG meeting held at Manchester Digital Development Agency

Thanks to all those who attended and congratulations to the lucky Vista winners… You know who you are.

Generic Methods… Now there’s a thing

Like the rest of the .NET world I have been soaking up the classes in the System.Collections.Generic namespace which have saved me a shed load of lines of custom collection code.

The other day I was writing some CodeSmith templates and needed a class to represent a property that could be hydrated from an XmlNode. And thus I began…

private XmlNode _propNode; 

public string Name 




        string attName = "name"; 

        //check the attribute exists 

        if (_propNode.Attributes[attName] != null) 

            //it does so return it 

            return _propNode.Attributes[attName].Value; 

        //it doesn't so return an empty string 

        return string.Empty; 



After the first few properties I realised I needed to refactor the XmlNode reading out as I was going to have about 20 properties that did the same thing. The problem was that the Value property of the Attribute returns a string so I was going to have to do some type conversion and so would need a method for each type string, int and bool that I needed. I seemed to recall reading about Generic methods and so I investigated… As it turns out I ended up wrapping this method with a method for each type anyway but I discovered Generic methods along the way which I’d not taken advantage of before.

public void GetAttributeValue<T>(ref T attValue, 

    XmlNode nodeToParse, string attName) 


    //check the attribute exists 

    if(nodeToParse.Attributes[attName] != null) 


        //get the string value 

        string strVal = nodeToParse.Attributes[attName].Value; 

        //set the attributeValue that has  

        //been passed in by reference, casting it 

        //from an object using the Generic parameter 

        //and using its own type to perform the conversion 

        attValue = (T)Convert.ChangeType(strVal, 


        attValue = (T)Convert.ChangeType(strVal, 




You can’t specify a Generic return type so you get the value out by passing in an argument by reference. So, you call this method like so:

public bool IsPrimaryKey 




        //set your default value here 

        //that is returned if the attribute 

        //doesn't exist 

        bool returnVal = false; 

        //call the method specifying the type 

        GetAttributeValue<bool>(ref returnVal, 

            _propNode, "isPrimaryKey"); 

        return returnVal; 



This allowed me to use the same method for all of the types of parameter I wanted to fill from the XmlNode’s attributes.

In the end this didn’t save me a great deal of code from doing it without using Generics and I still ended up casting the return value from an object so there would be no performance benefit either (not that performance was an issue here) but it is definitely an interesting language feature that I am sure I will find more uses for…

Visual Studio on Vista

This all looks a bit alarming… The gist being that none of Microsoft’s dev tools for the .Net framework are fully compatible with Vista and only VS2005 is ever going to be. This leaves mine and everyone else’s 1.1 projects out in the cold as far as Vista is concerned.

There are lots of efforts around to get VS 2005 building against the .Net framework 1.1 but surely, especially in light of the fact that the Windows folk claim it is a piece of piddle to get your applications to run on Vista, we should be able to run 2003.



Jonathan Allen links to a bit of Microsoft opinion on this issue… The official line lies between “great progress w/Vista on the security front” and “We are just as (financially)constrained as everyone else”. In some ways I can buy the first one. Security is a trade off and generally, to get the benefits, you have to give up something. Whilst the second one may be true in that the dev tools folk no doubt have a budget and a finite amount of resources I don’t think it is a good choice of argument to pacify the VS using public. As it happens, it also turns out that most of VS2003 will work if you are running as admin so hopefully it isn’t going to be too much of an issue.

Vista RC1… Feel the pain

In my earlier post on Vista in Virtual PC 2004 I mentioned some of the troubles I had installing and running Vista RC1. Scott Hanselman posted yesterday about some of the issues, rather all of the issues (I hope as there is a big old list of them) that he has come across since taking the plunge to install on his ‘everyday’ machine. Sounds like it has made a right mess of it.

I like that way he points out that he is still ‘stoked about Vista’ despite the fact it has buggered his machine up. Never say die…

I reckon if Scott Hanselman (without lavishing too much praise in his general direction) is having trouble then there isn’t much hope for the rest of us…

So what does RC stand for then?

  • Retreat Cautiously
  • Really Crap
  • Return at Christmas

Any suggestions?

VBUG Manchester Meet…

Continuing my hectic week of nerd community events (two is hectic by my standards) I attended a VBUG doo in Manchester yesterday evening. The presentation was an overview of the of the newly named, and with characteristic verbosity of course, ASP.NET 2.0 AJAX Extensions and was ably delivered by Gary Rowntree.

The presentation only briefly touched on the other elements of the ‘Atlas’ framework but did cover the server side of things in a fair bit of depth, particularly the update panel and the process it utlises to weave its magic.

I have used all kinds of terribly hackish methods for doing away with obvious page postbacks in the past, which generally involved stashing a hidden page in an iframe or sneaky window, but I haven’t really scratched the surface of the frameworks that are available now. So I’m no expert but what I would say is that we should all give it a little bit of thought before using asynch callbacks for everything. Alex Bosworth has an interesting list of AJAX no nos on his blog. The ease of the update panel might make AJAX monsters of us all…

I stumbled today on a new podcast that I hadn’t listened to before and funnily enough the current episode (show, cast, release… what do you call them?) is about the client library side of the Atlas set up which is the bit that was largely absent from Gary’s talk. The podcast is by Wally McClure and can be found here and includes a demo video.

If you fancy going to any of the Manchester VBUG meetings should keep an eye on the listing or get in touch with VBUG.

Vista RC1 on Virtual PC 2004

I have finally got Windows Vista RC1 going in a virtual machine on my laptop. I started with it yesterday and I have to say it wasn’t the smoothest ride. That isn’t to say it is Vista’s fault but more getting it to play nicely in a virtual machine. The first couple of attempts were slow and unstable, so much so that I couldn’t actually get it not to freeze for long enough to get the virtual machine additions installed.

On a browse around the web this morning I discovered that according to Mike Kolitz (and he should know as according to his bio he is on the Virtualization team) the VM Additions that you need for the RC1 build are cunningly hidden inside the iso that comes when you install Virtual Server 2005 R2 Beta 2. You need to install that first and then attach the iso that ends up in your programs folder to the virtual machine for installation. Why they aren’t available seperately is anyones guess but there they are.

Once I managed to get those installed everything was hunky dory. Well, almost everything except I had no Internet connectivity. After a lot of prodding around I discovered that the Virtual Machine Network Services that are required on the host machine network connection had been mysteriously disabled. Virtual Server perhaps? Who knows but having enabled them again all was well.

I was hoping that, armed with the appropriate VM Additions I would get the Aero interface but alas, the emulated graphics card in Virtual PC doesn’t appear to be up to the task. I didn’t even realise that it emulated a graphics card so I spent a fair while trying to get the drivers for my card into the VM thinking that their absence was causing my initial woes… Well… you live and learn.

As for Vista, it looks great. I don’t think you can really give an informed opinion on an operating system until you use it ‘in the trenches’ but it is looking good so far.

Unit Testing isn’t necessary once you get a bit of experience down you…

What a crock. Following hot on the heels of Phil’s ‘Old developers get on my nerves and smell of soap’ post (not altogether accurate quote, more paraphrasing) I stumbled, via hanselminutes across this load of old tosh…

It appears that once you have 21 years of development experience under your belt you can divine whether your code works correctly using the force.

I have not really got into ‘Test Driven Development’ myself, now that isn’t to say it hasn’t got its merits, but my brain doesn’t work that way at the moment. I at least get a class defined with some method stubs in before I think about unit tests. I very often fill the methods out and I am sure there will be XP purists that balk at that.

I have in the last year written an application that because of time pressure I decided to do away with writing the unit tests. I think this is a reasonable decision to take if there just isn’t room to fit them in. I wish I had though as six months later the client was back for some new features that involved a bit of a reworking of some of the old stuff and it was a nightmare without the unit tests available.

You see, I am of the opinion that to consider unit tests as purely a time consuming mechanism for finding bugs is to undersell them. Bugs will out eventually, unit tests or not but the big thing for me, and the thing that gives the payback for writing them in the first place is when you come to do some refactoring or other. Particularly when things have got a bit out of hand. To be able to instantly see what has broken as a result of your changes is where it is at for me with unit testing. You also can’t argue that if you are able to automatically run a defined, possibly 100%, amount of your public APIs with every build then you are going to have a more robust application at the end of it than if you arbitrarily give it a manual runout.

The ‘time consuming’ argument is not really holding water these days either. I mean, you still have to write some stuff but there are plenty of tools that can lend a hand. Just out of the ones I have had a play with you have CodeRush that has some templates, Visual Studio will generate tests for you that need a bit (or a lot at times) of editing and there is nothing stopping you generating them with CodeSmith or any of the other miriad of code gen tools.

Judging from the comments Wil Shipley isn’t alone. I don’t mind people like that though…

…because they are wrong.

What a TODO

One of my most used features in Visual Studio over the last couple of versions has been the //TODO comment (apart from things like the code editor, the debugger etc before some smart arse points that out). Due to my over-enthusiastic social life as a youth I am not blessed with a great deal of memory, I mean in my brain as opposed to my computers where I have plenty. Consequently I find it difficult to keep track of everything I plan to do while I am writing code. I suppose, amnesiac or not, we all do when the classes start mounting up and the solutions swell.

So, for me the //TODO comment is a life saver, at least, it could be a life saver if the darned thing worked properly. I am sure it works as intended but I fail to see why the TODO Team or whoever was responsible for it limited the task list to only show TODO comments from currently open files. Not to say that this isn’t useful but, as the files are open, I could probably find those myself in a couple more seconds than it takes me to look at the task list. Valuable workflow time I agree but not as valuable as the time I lose on all of the TODOs that lurk unnoticed in all the unopen files.

Being a bit of a Flash and more recently Flex noodler I was pleased to find the TODO plug-in for FlexBuilder/Eclipse. Downloaded… Installed… works like a treat. As you add a TODO it turns up in your task list and there it stays until the TODO is TODONE. Why can’t we have this in Visual Studio?

To that end I rustled up a quick console app that you stick in the root folder of your project/solution and run. Tell it whether you are looking for .as (I did this before I started with Flex and its plug-in) or .cs files and it recurses through your folders and files and gives you a list of all your TODOs and where they are. It also counts the lines of code, excluding comments and lines that only have a curly brace on while it is at it. Am I particularly proud of myself? Well no, it is a stupid application with about ten lines of code in it but I was desperate to actually have something codesque on my blog and it was the only thing I could think of. It has also been really handy for keeping track of my TODOs so perhaps I’m being a bit harsh on myself there. I haven’t posted the source because there isn’t anything exciting in it, apart from a keylogger and a couple of trojans, but if any of my regular readers, sorry, if either of my regular readers would like it then let me know…

On that note, how the hell do you attract traffic to your blog? I have tried a couple of things with varying degress of success but am yet to pass 40 readers… Maybe that is another post.

RSS My Last.Fm

  • An error has occurred; the feed is probably down. Try again later.