2015-10-17 19 views
0

我創建了一個新的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

+0

另請參閱http://stackoverflow.com/questions/11854308/why-am-i-getting-error-cs0246-the-type-or-namespace-name-could-not-be-found – Amitd

回答

1

您拼錯了類型或名稱空間的名稱嗎?沒有正確的名稱,編譯器無法找到類型或名稱空間的定義。這經常發生是因爲用於該類型名稱的外殼不正確。例如,數據集ds;生成CS0246,因爲數據集中的s必須大寫。

查找更多關於CS0246 at MSDN

+0

我不dont這麼認爲...繼承我的代碼,我編輯了這篇文章。是否有可能我不能在asp.net api服務器中添加這樣的引用?即時通訊這個環境中的新手:/ –

+0

更新2:http://imgur.com/v7DC6me –

0

您正在使用不正確的項目類型。 您需要使用.Net Framework,而不是.Net Core。