我創建了一個新的ASP.NET 5項目,以Rest示例開始。 我創建了一個控制器,工作很好。ASP.NET 5添加外部/系統程序集
我想在本地主機上運行服務器。我想使用的組件「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,它什麼都不做,如果我嘗試使用它,同樣的錯誤appers,因此它與所有引用的DLL發生的事情,我在做什麼錯?
Update2: 嗯,也許這是原因? http://imgur.com/v7DC6me
另請參閱http://stackoverflow.com/questions/11854308/why-am-i-getting-error-cs0246-the-type-or-namespace-name-could-not-be-found – Amitd