繁体   English   中英

System.dll中发生了类型为'System.InvalidOperationException'的未处理异常

[英]An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll

我正在执行以下代码:

class Program
{
    static void Main(string[] args)
    {
        PerformanceCounter performanceCounter = new PerformanceCounter("Network Interface", "Bytes Sent/sec", "Intel(R) 82579V Gigabit Network Connection");
        Console.WriteLine(performanceCounter.NextValue().ToString());
    }
}

我收到这个例外。

System.dll中发生了类型为'System.InvalidOperationException'的未处理异常。其他信息:指定类别中不存在实例'Intel(R)82579V千兆网络连接'。

我已经使用Windows perfmon工具测试了参数,它正在工作,但是在代码中给出了异常。

有人可以帮忙吗..

您是否检查过拼写正确的名称? 即使有小错误,这也很可能行不通。

要检查此类别中存在哪些名称,请尝试(如此处建议的那样: https : //stackoverflow.com/a/29270209/1648463

PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");
String[] instancename = category.GetInstanceNames();

foreach (string name in instancename)
{
    Console.WriteLine(name);
}

例如,我计算机上网络接口的现有名称之一是

Intel[R] 82579LM Gigabit Network Connection

(使用方括号代替圆括号)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM