S h o r t S t o r i e s

// Tales from software development

Archive for March 2010

Another reason for 404 Page Not Found

leave a comment »

This morning I installed and configured a web application but couldn’t successfully access it from a browser. I had a test version of the same application running successfully on another server and couldn’t see any differences in the configuration of the web servers or the applications.

I tried everything I could think of but was still getting a 404 Page Not Found error.

I can’t recall having this particular problem before – it was because the IIS Web Service Extensions configuration was configured without permission for ASP.NET. I selected the entry for ASP.NET and then clicked the Allow button:

Written by Sea Monkey

March 25, 2010 at 8:00 pm

Posted in Environments

Tagged with

Static indexers are not supported in C#

leave a comment »

C# is a comprehensive language that covers most of the needs of a typical application software developer but once in a while I find myself trying to implement something a little unusual and discovering that C# doesn’t allow it. Often there’s a good reason but sometimes there isn’t.

How about static indexers ? I’ve never needed one before but I have a static class that’s used to hold lookup data. I wanted to provide an indexer so that the data could be enumerated as well as accessed directly through individual properties.

If you try this you’ll quickly discover that static indexers aren’t supported because as soon as you omit the ‘this’ part of the indexer signature the compiler doesn’t have any idea of what you’re trying to do. You’ll get syntax error messages like “Array size cannot be specified in a variable declaration”.

Googling “c# static indexer” turned up a load of hits confirming that C# doesn’t support this but one particular thread provided some interesting comments from Microsoft’s Eric Gunnerson.

The bottom line ? The C# team didn’t think it was worth the effort…

Written by Sea Monkey

March 24, 2010 at 7:00 pm

Posted in Development

Tagged with ,

Comparing file timestamps on NTFS and FAT32

leave a comment »

I’ve just bumped into a problem with file timestamps that I’ve encountered before and decided to research it a little more thoroughly this time around.

I was working on a utility that runs as a service and keeps a set of files in sync across several disks. The files’ Last Write timestamps are used to determine if a file has been updated and needs to be copied to keep the other copies of the file in sync.

Everything worked fine in my development environment but when the utility was deployed to the customer’s server we immediately noticed that the files were always being copied from one particular disk to another whenever it ran. The source disk was an NTFS formatted 500GB disk and the target disk was a 32GB SSD formatted as FAT32. This immediately set alarm bells ringing in my mind as FAT32 file timestamps don’t hold date/time information to the same resolution as NTFS.

NTFS stores all timestamps to 100 nanosecond resolution. By comparison, FAT32 stores the time portion of a timestamp to a 2 second resolution. There is an additional field that holds additional time information at 10ms resolution for the Create Date/Time only.

I updated the utility to allow a discrepancy of up to 2000 ms (i.e. 2 seconds) when comparing timestamps if the source and target disks are formatted with different filesystems. I also added some debugging code to identify the maximum discrepancy that was found when no files had been changed to confirm that the 2000 ms value was sufficient.

The largest discrepancy found when running against 14,000 files totalling 2.5GB was 1994 ms. So, the 2000 ms value looks to be sufficient.

Written by Sea Monkey

March 22, 2010 at 8:00 pm

Posted in Development

Tagged with ,

Read/Write speeds

leave a comment »

I don’t usually pay too much attention to the read/write speeds given in disk and flash drive reviews because I doubt that I’d really notice the difference of a few KB/s when speeds are measured in MB/s. But I’ve just done a quick survey of the read/write speeds of various devices attached to my development laptop and was surprised by some of the results.

I used Totusoft’s free LAN Speed Test utility. This simply writes some data to a file and then reads it. Reading and writing to a file share gives an indication of real world network performance. I used the default data size of 100Mb.

What got me started on this is that my broadband modem and a couple of servers are in a different location to most of my development PCs and the link between the two groups of devices is an ‘ethernet over power’ (EOP) type link. This is rated at 200 Mpbs although I was aware that, realistically, I was probably only getting around 40-50 Mbps. I’ve been meaning to run a CAT5/6 cable between the two groups and thought it would be useful to measure the performance of the link to see how much benefit I’d get.

When I ran the LAN Speed Test utility it gave me a result of 4 Mbps write (outgoing) and 2.5 Mbps read (incoming). I was shocked by this as it’s an order of magnitude less than I’d expected. I bypassed the EOP link using the built-in 54G wireless NIC in my devolopment laptop and got 19.2 Mbps write and 19.6 Mbps read. Things must be bad if a 54G wireless connection is 5 times faster than the EOP link!

Then I ran some more speed tests with the following results:

Device        Write (Mbps)  Read (Mbps)  Description
LAN EOP                4.0          2.5  LAN PC-PC ethernet-over-power link
LAN 54G               19.2         19.6  LAN PC-PC 54G wireless link
LAN Gigabit          287.6        276.7  LAN PC-PC gigabit ethernet link via 1 switch
LAN Gigabit (2)      121.9        355.6  LAN PC-PC gigabit ethernet link via 2 switches
Internal SATA        273.8        213.3  Internal 2.5 inch SATA drive
USB SATA             130.0        174.6  USB attached external 3.25 inch SATA drive
USB Flash             32.0         87.8  USB Flash drive
SDHC                  64.0        133.0  SanDisk Ultra III SDHC in internal card reader

The main surprise is that reading and writing over a gigabit LAN is faster than accessing an internal hard disk. I was sceptical enough to rerun this test a few times but the results were consistent. The test was reading/writing from my development laptop to a server, both with gigabit NICs and connected via a NetGear ProSafe unmanaged gigabit switch.

The performance of the EOP link was so poor that I decided it was time to replace it with a network cable. To make the most of the Gigabit NICs installed in some of the PCs I also purchased another NetGear ProSafe gigabit unmanaged switch to replace the built-in 100mbps switch of the broadband router/modem. I repeated the EOP test using the same two PCs. The link was now PC-switch1-switch2-PC (both switches are NetGear ProSafe switches). The result is shown as ‘LAN Gigabit (2)’. Replacing the EOP with a cable gave a 30 times improvement in write speed and a 142 times improvement in read speed. Again, I was sceptical of the reported read speed but I repeated the test several times and got the same result. Even increasing the data size to 1Gb to rule out caching didn’t significantly change the result.

The difference in performance between a USB flash drive and an SDHC card inserted into my development laptop’s integrated card reader also provided a small surprise. I thought they’d be about the same or that the SDHC card might be a little bit slower. This particular card is a SanDisk Ultra III high speed card optmised for use in digital cameras which might explain why it was so much faster than then USB flash drive.

Written by Sea Monkey

March 19, 2010 at 8:00 pm

Posted in Hardware

Tagged with ,

audiobooks.com: a lesson in privacy invasion

leave a comment »

I’ve recently started getting unsolicited emails from Audiobooks.com. I’ve never purchased anything from them and haven’t bought an audio book for at least a couple of years. So, I assume they’re the kind of company that buys lists of email addresses from ‘providers’.

It’s bad enough getting spammed by this company but they really add insult to injury if you try to unsubscribe from their mailing list. First you get presented with this web page:

Ignoring the Your Name field I clicked the Send button only to get this:

Wonderful! A company that I’ve never heard of is sending me spam and is now insisting that I give them personal details before they’ll consider removing me from their email list ?

It’s difficult to understand the mindset of companies like this. How is this kind of behaviour going to do anything except alienate its potential customers ?

Written by Sea Monkey

March 17, 2010 at 8:00 am

Posted in Comment

Tagged with

Note to self: \r\n doesn’t work in a resource string

leave a comment »

I’m surprised that I haven’t hit this before now but placing escape sequences like \r\n in a resource string doesn’t work. The reason is simple enough: these escape sequences are handled by the C# compiler when compiling C# source code. They have no effect when ‘seen’ at runtime.

You can embed a newline in a resource string using Shift+Enter but once you start thinking about it, embeddding newlines in resource strings probably isn’t such a good idea anyway. If your resource strings are translated into other languages then it might be useful to have some flexibility about where  the newlines are placed.

My solution was to add a composite formatting placeholder and use Environment.Newline to replace it.

Resource string: {0} started successfully.{1}Listening for connection requests...

Console.WriteLine(Resources.Msg0001, Application.ProductName, Environment.NewLine);

Written by Sea Monkey

March 15, 2010 at 8:00 am

Posted in Development

Tagged with ,

UdpClient – Getting the sender’s IP address

with 2 comments

I’ve just written a SYSLOG server and stumbled a little on trying to figure out where I could find the sender’s IP address for logging purposes.

I’m using a UdpClient with EnableBroadcast set to true and calling the BeginReceive and EndReceive methods to receive data asynchronously. A message can arrive from any client, so how do you identify the client IP address ? Logically, it should be associated with the message data but I couldn’t find anything that referenced it.

The mistake I’d made was following the misleading example code for the UdpClient BeginReceive method on MSDN. (The link is for the .NET 2.0 but the documentation is unchanged in later versions.) If you follow the code carefully you’ll see that the local IPEndPoint is stored in the UdpState object that is passed into the callback specified by BeginReceive. This IPEndpoint is then used on the call to EndReceive.

You’ll notice that this argument is passed by ref. Why ? My guess was that it’s because it’s populated by the EndReceive method. I experimented and confirmed it. So, the code in the example isn’t technically wrong but it is confused and misleading. Passing details of the local endpoint to EndReceive so that it can overwrite them with details of the remote end point isn’t very useful and probably wasn’t what the writer of the example intended.

I’d suggest creating a new empty IPEndPoint in the ReceiveCallback method and passing this into the EndReceive method:

IPEndPoint senderIpEndPoint = new IPEndPoint(0,0);
Byte[] messageBytes = u.EndReceive(ar, ref senderIpEndPoint);
string messageString = Encoding.ASCII.GetString(messageBytes);

Console.WriteLine("{0} {1}", senderIpEndPoint.Address.ToString(), messageString);


Written by Sea Monkey

March 11, 2010 at 8:00 pm

Posted in Development

Tagged with ,