title: PerformanceCounter Category does not exist even though it exists
body: <p>I have an Azure Web Role and a separate Windows Service running on my IIS machine. Web role creates a custom performance counter category and two counters. I am trying to read the performance counters from my Windows Service. Even though <code>PerformanceCounterCategory.Exists(categoryName)</code> returns <code>true</code>, <code>GetCounters</code> method throws an exception saying <code>Category does not exist</code> (see update).</p>
  
  <pre><code>if (PerformanceCounterCategory.Exists(categoryName))
  {
      try
      {
          // Get the existing category and counters
          PerformanceCounterCategory existingCategory = new PerformanceCounterCategory(categoryName);
          counters = existingCategory.GetCounters();
      }
      catch (Exception e)
      {
          Debug.WriteLine("Failed to read the performance category {0}. Exception: {1}", categoryName, e.Message);
      }
  }
  </code></pre>
  
  <p>Windows service runs as a local system service, so it should have privileges I think. In fact, I am able to see performance category and counters via Visual Studio's Server Explorer.</p>
  
  <p>If category doesn't exist, I should expect <code>PerformanceCounterCategory.Exists(categoryName)</code> to fail in the first place, right?</p>
  
  <p>UPDATES</p>
  
  <ul>
  <li>I saw <code>GetCounters</code> method throw <code>InvalidOperationException</code> with message <code>Could not Read Category Index: {some index here}.</code> too.</li>
  <li><a href="https://social.msdn.microsoft.com/Forums/en-US/7cb547e2-d13e-4ede-b042-38627675e321/trying-to-read-performancecounter-getting-could-not-read-category-index-" rel="nofollow">Similar issue</a> posted on msdn forums</li>
  <li>The same process is able to read the counters fine.</li>
  </ul>