Microsoft@Open Mic Night

In: Programming

9 Dec 2012

What The FileReadingExceptionIf you’re a programmer, or even just a bro-grammer, check this comment on the official .NET documentation out:

Offset and position parameters wrong in intellisense
Its *really* annoying when the Intellisense documentation is wrong when you are coding … it has been a frustrating exercise to figure this out. As a previous poster mentioned, the Intellisense doco for the offset and position parameters are swapped around. The parameter descriptions as shown on this page are correct.

.NET intellisense pulling a dick move

Screencap of the “sligtly” misleading intellisense description from VS2010.

And let me just add that I would only stumble upon comedy gold like this after having had the most inexplicable out-of-bounds exception ever. Here is some simplified code that will throw an out-of-bounds exception on the 2nd read when reading from a file of 8 bytes or more:

using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KeyValueBase.Interfaces;
using System.IO;
using System.IO.MemoryMappedFiles;

public class SomeClassName
	public void Init(String indexfile)
		uint[] keypair = new uint[4];
		var mmName = Path.GetFileName(indexfile);
		using (var mStream = new FileStream(indexfile, FileMode.Open)){
			using (var mmf = MemoryMappedFile.CreateFromFile(
				mStream.Length, MemoryMappedFileAccess.Read, null,
				HandleInheritability.None, false)){

				using (var a = mmf.CreateViewAccessor(
						0, mStream.Length,
					for (int i=0; i<mStream.Length; i+=2*sizeof(uint)){
						/* The wrongly documented function that leads
						 * to the most inexplicable out-of-bounds 
						 * exception.
						 * The following line is well behaved */
						a.ReadArray<UInt32>(i, keypair, 0, 4);
						/* This line on the contrary does something 
						 * "funny" with your program, try it! */
						// a.ReadArray<UInt32>(0, keypair, i, 4);

I would of course be the last to want to generate negative prejudice towards the entire subspecies of .NET dependent bro-grammers, but I think it is fair to assume that this error would have been patched a long time ago if they in general were more prone to and proficient in dealing with binary data ;)

1 Response to Microsoft@Open Mic Night



December 10th, 2012 at 13:32

Well at least they’re consistent with this error throughout the entire class:

Comment Form

About this blog

The name is inspired by the saying: "perfection is the bane of all good things".
Read more