Tuesday, April 20, 2010

.Net 4 VS2010 Conversion Notes

I'm in the process of converting a bunch of projects from .NET 3.5 to .NET 4.0 and know that I will be converting plenty more in the future so I thought I'd jot down some notes as I went along. This list of notes should increase over time.

 

Machine.Config

.NET 3.0 and 3.5 were really an extension of .NET 2.0 so the machine.config remained constant here C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config or in the 64-bit equivalent here C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG

With .NET 4 we have new 32-bit and 64-bit locations here C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config and here C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config

If you've made modifications to your machine.config file for .NET 2.0, 3.0, or 3.5 then you'll have to propagate those changes to the .NET 4.0 version.

 

Links to conversion resources

Official What's new in ASP.NET MVC 2

ASP.NET 4 Breaking Changes

 

Breaking Changes that I've bumped into

<httpRuntime requestValidationMode="2.0" /> needs to be added to web.config to prevent the "A potentially dangerous Request.Form value was detected from the client" error.

 

Tuesday, April 13, 2010

Merging in Mercurial

I'm using TortoiseHg and trying to get the hang of merging changes from multiple contributors so I setup a small test and did some changes and commits and pulled each one into a main repository without doing any merges (except one at the beginning). This is what the tree looked like.




 Then I tried to do a number of different merges and found that nothing really worked (or in the end made sense) except for merging from the bottom of the graph to the tip. When I started doing this things started flowing smoothly. I had lots of conflicts because I made sure that each time I changed a file I changed the same line in different locations to force conflicts. The conflicts were easily resolved in the default KDiff3 text merge tool. This is what the graph ended up looking like in the end.



Saturday, April 3, 2010

Windows Home Server - the good and bad

About ten months ago I bought and setup a Windows Home Server on my home network. Since that date I've used it twice for recoveries.

I follow the three rules of "backup reality", i.e. if these 3 criteria aren't met then I don't consider it a real backup:

  1. If must be automated.
  2. It must be redundant.
  3. It must be duplicated off-site

This is a must for any business (even though many don't do this) but it's a pretty tall order for a home network. I find that Windows Home Server with Amazon S3 syncing gives me all this.

They say that an untested restore of a backup is no backup at all.

The first time I got to try out the restore feature of the server was when I upgraded the hard disk on a Server 2003 server from 250GB to 2TB. This was the perfect opportunity to try out the WHS restore feature. I let the nightly backup complete and in the morning I swapped out the drives, put in the restore disk and rebooted the machine. WHS recognized the machine and picked the correct backup and target and a few hours later the server was back up and running on a new hard disk. I was a bit surprised at how long the restore took, I remember it being several hours. I know that it also had to format the hard disk but still thought that it was longer than I would have expected.

The second time I got to try the restore was when I was unable to sign on to a Windows 7 Ultimate machine. Win7 just told me that my password was invalid. I could boot in safe mode and sign in but not in regular mode. I signed in using safe mode and moved the most recent data set to a USB drive and tried a number of troubleshooting recovery steps. Searches showed that this type of problem was being experienced by many Windows 7 users but no fix has come from Microsoft yet and none of the suggested workarounds had worked for me. So I attempted to do a restore from WHS. On booting with the recovery CD it wasn't able to correctly mach up the disk. That machine has 128GB Solid State Drive (SSD) as the boot drive and a 2TB drive as the secondary drive. The restore automatically picked to restore the boot drive to the 2TB drive which was the wrong one. That was easily changed using the restore UI but after the restore had been running for a couple of hours and completed about 80% of the restore it failed with a networking error. That networking error was also found all over the net with plenty of people experiencing the same type of error almost at the end of their restore. None of their workarounds worked for me. So my next and final recovery step was to re-install the OS. I did this and it still had problems booting.

Now the one thing that I didn't tell you about this machine was that when I put it together I had inadvertently wired the SSD boot drive as drive 1 and the 2TB data drive as drive 0. After putting the case back together and starting the machine I saw the problem and when into the bios and changed the boot drive to be the non-default 1 (from the default 0). This I believe was the source of most of my problems. My theory is that deep in the bowels of Windows 7 and many other pieces of device software written by many companies the boot drive is frequently assume to be 0 and this is often hard coded. Because the boot drive is rarely anything else this type of bug is hardly ever seen.

I opened up the case and switched the wires around and made the boot drive 0 and the data drive 1 and that was the first time in days that the machine had operated in a normal manner and this time it finally booted with my re-installed OS. Since then it has been running way smoother and I attribute this to the non-standard drive wiring that I had done. Even though it's supposed to be able to work the other way I just don't think that it's worth the risk to do that again. Drive 0 will always be my boot drive in the future if I have any choice.

 

Tuesday, March 30, 2010

Number of TFS checkins

I was trying to work out how many times I have checked code into TFS for each project that I've worked on in a given date range. I still haven't managed to work out how to break it down by project but did get the total count.

  • Ran Team Foundation Sidekicks.
  • On History tab select my User name in the drop down.
  • Clicked the "Save list to file" button.

Problem with this CSV list is that I have line breaks in many of the comments so it's not a true CSV file.

  • Using Notepad++
  • Ctrl+F for search and change the Search Mode to Regular Expression.
  • Enter "^\d+," without quotes in the Find what field.
  • Click the "Find all in Current Document" or the "Count" button to get the number of lines with that pattern.

That will be the number of items that you checked in.

The regex ^\d+, can be roughly interpreted as find all lines starting with (^) a string of one or more numbers (\d+) and ending with a comma (,).

This is probably one of the most unwieldy and ugliest solutions to a problem I have recently come up with. Also, I haven't managed to work out how to breakdown check-ins by project. Any ideas?

Wednesday, March 24, 2010

Mercurial Commit Push Pull Update

I'm just starting to wrap my head around Mercurial and feel that this is the best diagram that I've seen that explains the push/pull commit/update model.
 To get or retrieve changes from your working directory to the "server" directory is always a two step process.
To "check-in" you will commit your changes to your local repository and then push them to the server.
To "get latest" you will pull from the server and then update to your working directory.

 

Source: http://www.ivy.fr/mercurial/ref/v1.0/Mercurial-QuickStart-v1.0-300dpi.png

Wednesday, March 17, 2010

Make Better Software: The Training Series

The company that I work for recently bought my team the Make Better Software: The Training Series done by Joel Spolsky at Fog Creek Software. This is my report on this course.

I've listened to all the Stack Overflow podcasts with Jeff Atwood and Joel Spolsky and so I now "get" that Joel is only pretending to be arrogant and his manner is intended to provoke debate. He does it well.

The six one-hour videos in the course are very well done. They were easy to watch and packed with good content and extremely well edited. Every now and then you felt like it was teetering on the edge of a sales pitch for either the product that they sell or for candidates to apply for a job at their company but considering that it was all about working at Fog Creek and creating Fog Bugz it would have been very difficult to not do this now and then.

The manual (Student Guide) that comes with the videos was not as well prepared as the videos. It is essentially a collection of Joel's blog post over the last 10 years divided into six sections. I found at least two blog posts that were repeated verbatim in two different sections and there were paragraphs that were repeated and some of the blogs seemed to have text missing off the end. This was slightly unprofessional and a bit irksome. I'm not sure if anybody proofread or edited the compilation of these.

In the table of contents he has a "chapter" titled "Incentive Pay Considered Harful", italics and bold are mine. I've heard Joel criticize candidates for submitting resumes with spelling mistakes in them with comments like "there's no excuse for that, don't they know how to use a spell checker."

Despite my criticism of the spelling and lack-of-proof-reading I consider the content to be good. It duplicates what is said in the video and in some parts goes a bit deeper and has the names and references that you might miss when watching the video of that section.

The course starts off with The Joel Test. We score fairly high on the Joel test with a 10. We don't do point 3 (daily builds) but instead we build on every check-in which is more rigorous than he is proposing.

After the Joel Test the course is divided into 6 modules:

  1. Recruiting
  2. Team Members
  3. Environment
  4. Schedules
  5. Lifecycle
  6. Design of Software

From a management point of view all modules are relevant but more so modules 1 to 4. I felt that Program Managers were the main focus in the Team Members section but all members were covered and some myths dispelled.

Fog Creek appear to have the best environment for almost anybody to work in let alone developers. It's interesting that the offices given to developers are not only to increase productivity but are a huge sales tool in recruiting talent.

My point of view is that of a developer. As such I found the second half of the course more interesting. Joel did an excellent job of convincing me about the value in specifications and I no longer feel that they are a waste of time but rather something that needs to be continuously worked on while a project is alive.

Would I recommend this course? Absolutely.

 

Tuesday, March 2, 2010

LINQ secondary sort using extension method syntax

You have a list of objects that you want to sort using LINQ. You want to sort by a primary and secondary key from the fields (properties or members) of the object. How do you do this?

The answer is to do two sorts. The first by the secondary key and the second by the primary key. Here's a little test console app that you can run to verify.

class Widget
{
    public int First { get; set; }
    public int Second { get; set; }
}
class Program
{
    static void Main(string[] args)
    {
        List<Widget> widgets = new List<Widget>();
        widgets.Add(new Widget { First = 1, Second = 6 });
        widgets.Add(new Widget { First = 2, Second = 6 });
        widgets.Add(new Widget { First = 3, Second = 5 });
        widgets.Add(new Widget { First = 4, Second = 5 });
        widgets.Add(new Widget { First = 5, Second = 4 });
        widgets.Add(new Widget { First = 6, Second = 4 });

        var firstSort = widgets.
          OrderByDescending(a => a.First).
            OrderBy(a => a.Second);
        foreach (Widget widget in firstSort)
        {
            Console.WriteLine("First {0} Second {1}",
                widget.First, widget.Second);
        }

        Console.ReadLine();
    }
}

The results of this run are:

First 6 Second 4
First 5 Second 4
First 4 Second 5
First 3 Second 5
First 2 Second 6
First 1 Second 6
Hit return to continue...

So we initially reverse sort by the First property, this will be the secondary sort. We then sort by the Second property, this will be the primary sort.