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

本文关键字:系统 程序集 外部 添加 NET ASP | 更新日期: 2023-09-27 18:18:04

我创建了一个新的ASP。NET 5项目,从Rest示例开始。我创建了一个控制器,工作得很好。

我想在本地主机上运行服务器。我想使用的程序集是"System"。诊断程序,以获得有关我的电脑硬件的一些信息,并显示在一个网站上。

每次我想启动服务器进行测试,我得到:

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指令或程序集?参考?)

This is my 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

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

您是否拼错了类型或名称空间的名称?如果没有正确的名称,编译器将无法找到类型或名称空间的定义。这种情况经常发生,因为类型名称中使用的大小写不正确。例如,Dataset ds;生成CS0246,因为Dataset中的s必须大写。

查找更多关于 CS0246 MSDN

您使用的项目类型不正确。你需要使用。net Framework,而不是。net Core。