title: Azure autoscaling exception when trying to read performance counter
body: <p>I am working on an example from Microsoft that shows how to use autoscaling (<a href="http://www.windowsazure.com/en-us/develop/net/how-to-guides/autoscaling/" rel="nofollow">http://www.windowsazure.com/en-us/develop/net/how-to-guides/autoscaling/</a>). The worker role installed on the cloud generates a performance counter and locally, a console application reads this counter and applies autoscaling.</p>
  
  <p>Everything looks fine, the performance counter is available from WADPerformanceCountersTable and the console application accesses correctly to the storage but it cannot find the worker role inside WADPerformanceCountersTable. This is the generated exception:</p>
  
  <pre><code>Autoscaling General Error: 2001 : 
  Microsoft.Practices.EnterpriseLibrary.WindowsAzure.Autoscaling.DataPointsCollection.DataPointsCollectionException:
  Could not retrieve performance counter with name '\Processor(_Total)\% Processor Time'
  for target 'WorkerRoleExample' from the WADPerformanceCountersTable table. ---&gt; 
  System.ArgumentOutOfRangeException: Could not retrieve the role with alias 'WorkerRoleExample' from the service information store.
  Please review the service information store to fix this.
  </code></pre>
  
  <p>Configuration files of Autoscaling Application Block (both files are part of a console application):</p>
  
  <p>rules.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;rules xmlns="http://schemas.microsoft.com/practices/2011/entlib/autoscaling/rules"&gt;
    &lt;constraintRules&gt;
      &lt;rule name="default" enabled="true" rank="1" description="The default constraint rule"&gt;
        &lt;actions&gt;
          &lt;range min="1" max="2" target="WorkerRoleExample"/&gt;
        &lt;/actions&gt;
      &lt;/rule&gt;
    &lt;/constraintRules&gt;
    &lt;reactiveRules&gt;
      &lt;rule name="ScaleUpOnHighUtilization" rank="10" description="Scale up the web role" enabled="true" &gt;
        &lt;when&gt;
          &lt;any&gt;
            &lt;greaterOrEqual operand="WebRoleA_CPU_Avg_5m" than="60"/&gt;
          &lt;/any&gt;
        &lt;/when&gt;
        &lt;actions&gt;
          &lt;scale target="WorkerRoleExample" by="1"/&gt;
        &lt;/actions&gt;
      &lt;/rule&gt;
      &lt;rule name="ScaleDownOnLowUtilization" rank="10" description="Scale up the web role" enabled="true" &gt;
        &lt;when&gt;
          &lt;all&gt;
            &lt;less operand="WebRoleA_CPU_Avg_5m" than="60"/&gt;
          &lt;/all&gt;
        &lt;/when&gt;
        &lt;actions&gt;
          &lt;scale target="WorkerRoleExample" by="-1"/&gt;
        &lt;/actions&gt;
      &lt;/rule&gt;
    &lt;/reactiveRules&gt;
    &lt;operands&gt;
      &lt;performanceCounter alias="WebRoleA_CPU_Avg_5m"
                          performanceCounterName="\Processor(_Total)\% Processor Time"
                          source ="WorkerRoleExample"
                          timespan="00:05:00" aggregate="Average"/&gt;
    &lt;/operands&gt;
  &lt;/rules&gt;
  </code></pre>
  
  <p>services.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;serviceModel xmlns="http://schemas.microsoft.com/practices/2011/entlib/autoscaling/serviceModel"&gt;
    &lt;subscriptions&gt;
      &lt;subscription name="TestingWorkerRole"
                    certificateThumbprint="**************"
                    subscriptionId="**************"
                    certificateStoreLocation="CurrentUser"
                    certificateStoreName="My"&gt;
        &lt;services&gt;
          &lt;service dnsPrefix="**************" slot="Staging"&gt;
            &lt;roles&gt;
              &lt;role alias="AutoscalingApplicationRole"
                    roleName="WorkerRoleExample"
                    wadStorageAccountName="targetstorage"/&gt;
            &lt;/roles&gt;
          &lt;/service&gt;
        &lt;/services&gt;
        &lt;storageAccounts&gt;
          &lt;storageAccount alias="targetstorage"
            connectionString="DefaultEndpointsProtocol=https;AccountName=*****;AccountKey=*******"&gt;
          &lt;/storageAccount&gt;
        &lt;/storageAccounts&gt;
      &lt;/subscription&gt;
    &lt;/subscriptions&gt;
  &lt;/serviceModel&gt;
  </code></pre>
  
  <p>Worker role running on the cloud generates a performance counter:</p>
  
  <pre><code>public override bool OnStart()
  {
      // Set the maximum number of concurrent connections 
      ServicePointManager.DefaultConnectionLimit = 12;
  
      CreatePerformanceCounters();
  
      return base.OnStart();
  }
  
  private static void CreatePerformanceCounters()
  {
      DiagnosticMonitorConfiguration diagConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
  
      var procTimeConfig = new PerformanceCounterConfiguration();
      procTimeConfig.CounterSpecifier = @"\Processor(_Total)\% Processor Time";
      procTimeConfig.SampleRate = TimeSpan.FromSeconds(10);
  
      diagConfig.PerformanceCounters.DataSources.Add(procTimeConfig);
      diagConfig.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
  
      DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagConfig);
  }
  </code></pre>