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

  • Question

  • Hello,

    I've upgraded a windows service that's written in VB.NET from VS 2008/.NET 3.5 to VS 2010/.NET 4.0.  I can install it on my Win 7 64 bit machine, using installutil and it runs just fine.  On the 32-bit Win 2003 server, I see the following error:

     

    Message: In MyProd Access Sub InitializeComponent, error: System.InvalidOperationException: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.
      at System.Diagnostics.PerformanceCounter.InitializeImpl()
      at System.Diagnostics.PerformanceCounter.EndInit()
      at MyProdMyAppTracker.MyAppService.InitializeComponent()
    Category: General


    Any idea what I should look at first?

    Thanks,

    Charlie

    Wednesday, June 29, 2011 5:59 PM

All replies

  • I tried adding a read-only flag in the call to my PerformanceCounter constructors.  However, I got errors that the Category didn't exist.  I'm not sure what to put there:                         

     

    Me.oPerfCntThreads = New System.Diagnostics.PerformanceCounter("My Application Name", "Threads", True)
    

    Thanks

    Wednesday, June 29, 2011 7:05 PM
  • Charlie,

    There is a better forum for you quesiton.  I will move this thread over there.

     

    http://social.msdn.microsoft.com/Forums/en-US/perfctr/threads

     


    Bruce Adamczak Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you
    Wednesday, June 29, 2011 7:45 PM
  • Hello,

    I figured out what to pass for my categories.  I changed my constructors to something similar to:

     

    Me.oPerfCntThreads = New System.Diagnostics.PerformanceCounter("My Application Name", "Threads", False)
    

     


    Since I am trying to write to these counters, I changed the Readonly parameter to false.  I installed and ran the service on my dev (64-bit Win7) machine, it worked fine.  However, it fails with the same error as before on my (32-bit Win 2003 Server):

     

     

    Message: In MyProd Access Sub InitializeComponent, error: System.InvalidOperationException: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.
     at System.Diagnostics.PerformanceCounter.InitializeImpl()
     at System.Diagnostics.PerformanceCounter.EndInit()
     at MyProdMyAppTracker.MyAppService.InitializeComponent()
    Category: General

    I'm wondering if this could be a permissions issue?  Are there any groups to which I need to add the user that this service runs under?

    I checked and it's running under the same account on the servers where the older VS 2008/.NET 3.5 version is successfully running as the new VS 2010/.NET 4.0 version is failing.  Both servers are 32-bit Win 2003. 

    As I said earlier, the new VS 2010/.NET 4.0 version of the service installs and runs fine on my 64-bit Win 7 dev machine.

    Thanks


    Wednesday, June 29, 2011 9:34 PM
  • Well,

    On my Win7 x64 development machine, the reference to System was pointing to:

    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll

    This path doesn't exist on the Win2003 x32 servers, but it did have a copy in the .NET 4.0 GAC at:

    C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089

    I changed tried changing the reference in VS to point to the GAC, by browsing to C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089.  This seemed to work, but when I view the properties of System in my References I still see it point to:

    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll

    Hmmmm

    Wednesday, June 29, 2011 9:58 PM