C# 实例';[实例名称]';在指定的类别中不存在

C# 实例';[实例名称]';在指定的类别中不存在,c#,asp.net-mvc-4,asp.net-web-api,performancecounter,multiple-instances,C#,Asp.net Mvc 4,Asp.net Web Api,Performancecounter,Multiple Instances,我们正在webapi中为oracle数据库性能计数器开发项目 string pid = GetCurrentProcessId().ToString(); string instanceName2 =AppDomain.CurrentDomain.FriendlyName.ToString().Replace('(', '[') .Replace(')', ']').Replace('#', '_').Replace('/', '_').Replace('\\', '_');

我们正在webapi中为oracle数据库性能计数器开发项目

string pid = GetCurrentProcessId().ToString();

string instanceName2 =AppDomain.CurrentDomain.FriendlyName.ToString().Replace('(', '[')
        .Replace(')', ']').Replace('#', '_').Replace('/', '_').Replace('\\', '_');


instName = instanceName2 + "[" + pid + "]";
foreach (PerformanceCounter p in this.PerfCounters)
{                   
   string counterValue = string.Join("=", p.CounterName, p.NextValue());
    obj.textBox1.AppendText("\r\n" + counterValue);
}
以及在PerformanceCounter类中设置实例

PerformanceCounter perfCounter = new PerformanceCounter();
perfCounter.CategoryName = catagoryName;
perfCounter.CounterName = counterName;
perfCounter.InstanceName = instName;
读取计数器值的代码如下所示

string pid = GetCurrentProcessId().ToString();

string instanceName2 =AppDomain.CurrentDomain.FriendlyName.ToString().Replace('(', '[')
        .Replace(')', ']').Replace('#', '_').Replace('/', '_').Replace('\\', '_');


instName = instanceName2 + "[" + pid + "]";
foreach (PerformanceCounter p in this.PerfCounters)
{                   
   string counterValue = string.Join("=", p.CounterName, p.NextValue());
    obj.textBox1.AppendText("\r\n" + counterValue);
}
当我尝试读取计数器值时出现异常,例如,指定类别中不存在实例“[Instance Name]”。打开DB连接后,无法检测实例名称