簡體   English   中英

ASP.NET 5添加外部/系統程序集

[英]ASP.NET 5 Adding External / system Assemblies

我從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,它什么也不做,如果我嘗試使用它,會出現相同的錯誤,所以所有引用dll都在發生這種情況,我在做什么錯?

Update2:嗯,這可能是原因嗎? http://imgur.com/v7DC6me

您是否拼寫了類型或名稱空間的名稱? 沒有正確的名稱,編譯器將找不到類型或名稱空間的定義。 經常發生這種情況是因為類型名稱中使用的大小寫不正確。 例如,數據集ds; 生成CS0246,因為必須將Dataset中的s大寫。

MSDN上的CS0246查找更多內容

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM