【发布时间】:2015-10-17 14:50:12
【问题描述】:
我创建了一个新的 ASP.NET 5 项目,从 Rest 示例开始。 我创建了一个控制器,效果很好。
我想在我的本地主机上运行服务器。我要使用的程序集是“System.Diagnostics,用于获取有关我的电脑硬件的一些信息并将它们显示在网站上。
每次我想启动服务器来测试它时,我都会得到:
CS0246 C# 类型或命名空间名称“PerformanceCounterCategory” 找不到(您是否缺少 using 指令或程序集 参考?)
在这种情况下我该怎么办?
如果我可以提供可能有用的信息,请告诉我。
这是有问题的类:
using System.Diagnostics;
namespace DashBoardServer.Model.Hardware
{
public class NetworkInfo
{
public float kbitsIn;
public float kbitsOut;
private string usedInterface = "Realtek PCIe GBE Family Controller";
public NetworkInfo()
{
getInfo();
}
public NetworkInfo(string networkInterface)
{
this.usedInterface = networkInterface;
getInfo();
}
private void getInfo()
{
PerformanceCounterCategory performanceCounterCategory = new PerformanceCounterCategory(usedInterface);
string[] instances = performanceCounterCategory.GetInstanceNames();
foreach (string networkInterface in instances)
{
if (networkInterface == "Realtek PCIe GBE Family Controller")
{
PerformanceCounter performanceCounterSent = new PerformanceCounter("Network Interface", "Bytes Sent/sec", networkInterface);
PerformanceCounter performanceCounterReceived = new PerformanceCounter("Network Interface", "Bytes Received/sec", networkInterface);
kbitsIn = performanceCounterSent.NextValue() / 1024;
kbitsOut = performanceCounterReceived.NextValue() / 1024;
}
}
}
}
}
->
CS0246 C# 类型或命名空间名称“PerformanceCounterCategory” 找不到(您是否缺少 using 指令或程序集 参考?)
这是我的 project.json
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
},
"frameworks": {
"dnx451": {
"dependencies": {
}
},
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
更新: 我创建了自己的小 dll,它什么都不做,如果我尝试使用它,也会出现同样的错误,所以它发生在所有引用 dll 上,我做错了什么?
更新2: 嗯,也许这就是原因? http://imgur.com/v7DC6me
【问题讨论】:
标签: c# asp.net .net-assembly