Monday, May 14, 2007

The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly

This is a case of poor choice of error messages. What it really means is that the Performance Object Category does not exist. The solution is to load the performance counters from the source DLL. In the .Net case, this means running InstallUtil on the file in question. For older perfmon objects, use Lodctr.

Technical details:

If you attempt to load a performance counter with this code (existing Performance Object, non-existant counter):

PerformanceCounter newCounter = new PerformanceCounter("RealCategory","BogusName","Foo",true);

You'll get the very helpful error message: "Counter 'BogusName' does not exist in the specified Category."

If you use this code (non-existant Performance Object):

PerformanceCounter newCounter = new PerformanceCounter("BogusCategory","BogusName","Foo",true);

You'll get a slightly less helpful error message: "Category does not exist." . . . hmm . . would have been nice to know which category.

Now if you use that same call, but flip the readonly flag to false

PerformanceCounter newCounter = new PerformanceCounter("BogusCategory","BogusName","Foo",false);

You get this very unhelpful message: "The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly."

The trick at this point is figuring out who's trying to load a counter, and which one they're trying to load. The following code will locate a PerformanceCounterInstaller within an assembly, given a filename. Easy enough to list all the DLLs in a given space with DIR /S /B *.DLL, then run InstallUtil on the ones that turn up positive.


System.Reflection.Assembly assy = System.Reflection.Assembly.LoadFile(fileName);
Type[] publicTypes = assy.GetExportedTypes();
foreach (Type t in publicTypes)
{
if (t.BaseType.Name == "Installer")
{
Installer o = (Installer)t.Assembly.CreateInstance(t.FullName);
foreach(Installer i in o.Installers)
{
if (i.GetType().Name == "PerformanceCounterInstaller")
{
MessageBox.Show("Performance Counter Installer Found in Assembly " + fileName);
}
}
}
}

Taupo Fly Fishing

I spent the first weekend in May fly fishing with my friend Brent down in the Taupo region.



We stayed at a place called The Creel in Turangi. Turangi is allegedly "The Trout Fishing Capital of New Zealand".

Fly Fishing Behind the Creel

The Creel was right on the Tongariro river, so we were up fishing at the crack of dawn. After a break for breakfast, we relocated a bit further up stream.

That was a beautiful stretch of river, but we didn't catch anything all day, maybe because of the constant stream of whitewater kayakers paddling through our pools. ;-)


Kayakers in our Fishing Hole

At the very last minute, just as it got too dark to see our lines, Brent hooked one.


On day two we started fishing Lake Otamangakau. We had no luck there, despite seeing a constant stream of fish jumping out of the water on the far side of the lake. So we packed up and started the drive back. On the way we stopped in Tauramanui to fish the Whanganui river for an hour or so. By that time I'd had enough fishing for the weekend, so I spent some time taking photos.

Brent caught two small fish (smaller than the one above), and missed one big one. I was a mile or so down the trail, so there were conveniently no witnesses. ;-)


Tongariro River

Rotorua Marathon

This site provides a couple of really cool ways of visualizing marathon results. (Damn, I need to train more for the next one.) ;-)

Hopefully they'll use this site for the Auckland Marathon results as well.

Rotorua Marathon