My current server development for a client has been going well but this week I finally got to the point where I wanted to look at the peformance counters it was presenting and they weren’t showing up in perfmon. My daily development for most projects is on my x64 box and I was building the server in x86 mode and although it was registering its counter DLL correctly it was an x86 DLL and the x64 perfmon can’t load x86 counter dlls.
This is something that I knew all about from when I was developing the new version of the performance counter library and the performance counter installer includes the option to install 32bit and 64bit counter DLLs in “side-by-side” mode on x64 so that things ‘just work’. Unfortunately I wasn’t using the ‘intstall both DLLs’ function and the library didn’t bother to tell me that the DLL that I was installing was not going to work… So I fixed it.
The trick is validate the DLLs that the installer is given. We now open the DLL as an image file and examine some of the flags to determine if the image is a 32bit image or a 64bit image. If the image isn’t what we expect then we don’t install it. Whilst we’re at it we check that the entry points that you say are in the DLL are actually exported from the DLL. This makes it much less likely that your counter installation will work but your counters wont show up in perfmon. Finally I switched to using
Install32and64bitDlls() and fixed a bug in that which meant that the 64bit counter DLL was being installed into the SYSWOW64 directory rather than the system directory when we were installing from an x86 binary (note to self, remember to turn off the WOW64 file system redirection when doing this kind of thing)…
So now it all works nicely.
As always, these changes will be in the next release of The Server Framework, if you need them sooner then drop me an email.