Perflib V2 development in C# RRS feed

  • Question

  • I am developing custom counters using the PerflibV2 methods in Visual Studio 2008 C# and .Net Framework 3.51 SP1. 



    - .res file is built correctly (ctrpp and rc) and present in the project

    - the .xml schema is accepted by lodctr

    - but the Counterset (perf object) names do not display in Perfmon's list

    - instead the GUIDs are displayed and

    - "can't load counters" is displayed at an add (+)attempt in Perfmon 

    - both single and multiple instance CounterSets are present


    Counters have the attribute "reference" set.


    The application runs without any exceptions when the CounterSets are added, when counters are added and instances are created and counter data is updated.  Just not getting through to Perfmon.


    A C# sample built using a code snippet and .xml from a CMG (2007) presentation shows the same behavior.  A C version using the same .xml schema loads and the counters are visible in Perfmon.


    A sample in C/C++ from the SDK (I think) loads and displays its Countersets correctly and counters can be added (+) to the collection set.


    This seems to be a lodctr problem related to C#.  I think there is something I need to do to install or register the C# .exe (maybe prior to running lodctr), as the Vis Studio 2008 development environment is on a different system than my target Server 2008 system. 

    In searching MSDN I have found another C# example I'm going to work with, but very little of anyone doing custom performance counter development using PerflibV2 methods.


    Is there a cache of information somewhere I'm missing?  Has anyone encountered this problem?


    Is there a better forum I should move this post to?

    Thanks in advance for any answers.



    Tuesday, May 12, 2009 1:38 AM

All replies

  • Wstetson,

    Verify that the .res file is actually getting linked to your binary. There should be a line like below in your .csproj file:


    When you deploy your binary on the target, make sure to run lodctr /m:[yourmanifest].man.

    Make sure that the "applicationIdentity" attribute in your manifest points to your binary.

    If your binary has an associated .mui file, make sure that you deploy it on the target under the appropriate language directory (e.g. en-us) in the folder where the binary resides.

    Also, before going to PerfMon, check that typeperf /qx "your counterset name" returns all your counter instance names.


    PS: you can expect a working CSharp sample in Win7 RTM SDK (when it comes out) under Samples\WinBase\PerfCounters\Basic\CSharp.
    Tuesday, May 12, 2009 1:58 AM
  • Sanket

    A belated thanks for the reply.  I just found this again while researching UACs and realized I had not followed up.  The problem in this case was Server 2008 UAC rules.  My User Id is in the Admistrator group but it was not getting 'enough' privilege to execute lodctr successfully and lodctr didn't provide an accurate error message.  A colleague suggested 'runas administrator...' and several things became clear. 

    The counters loaded correctly, were visible in Perfmon, and I was able to execute the application in that same command box.  We are now nearing beta and I need to incorporate a manifest and set 'requestedExecutionLevel' to avoid having to pop into a 'runas...'. 

    The application is intended to run as a Service when released, so this will propbably be a moot point then.

    Even though I found a solution to my problem without returning here, these forums/blogs are a great resource. If my answer helps someone else, so much the better.

    • Proposed as answer by RPA601SG Wednesday, August 24, 2011 6:54 PM
    Monday, August 3, 2009 8:08 PM
  • Hey wstetson,


    Could you guide me where to look for sample C++ code for perflib? I too am having the same issue of "can't load counters" and I am running the application as an admin.

    Wednesday, August 17, 2011 7:32 PM