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

时间:2015-10-17 14:50:12

标签: c# asp.net .net-assembly

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

我想在我的localhost上运行服务器。我想使用的程序集是#34; System.Diagnostics,以获取有关我的电脑硬件的一些信息并在网站上显示。

每次我想启动服务器测试它我得到:

  

CS0246 C#类型或命名空间名称' PerformanceCounterCategory'   无法找到(您是否错过了使用指令或程序集   引用?)

在这种情况下我该怎么办?

如果我能提供可能有用的信息,请告诉我。

这是有问题的课程:

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'   无法找到(您是否错过了使用指令或程序集   引用?)

这是我的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

2 个答案:

答案 0 :(得分:1)

您是否拼错了类型或命名空间的名称?如果没有正确的名称,编译器将无法找到类型或命名空间的定义。这通常是因为在类型名称中使用的套管不正确。例如,Dataset ds;生成CS0246,因为数据集中的s必须大写。

CS0246 at MSDN

上查看更多内容

答案 1 :(得分:0)

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

相关问题