【问题标题】:ASP.NET 5 Adding External / system AssembliesASP.NET 5 添加外部/系统程序集
【发布时间】:2015-10-17 14:50:12
【问题描述】:

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

我想在我的本地主机上运行服务器。我要使用的程序集是“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 上,我做错了什么?

更新2: 嗯,也许这就是原因? http://imgur.com/v7DC6me

【问题讨论】:

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


【解决方案1】:

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

在CS0246 at MSDN上查找更多信息

【讨论】:

  • 我不这么认为...这是我的代码,我编辑了帖子。是否有可能我无法在 asp.net api 服务器中添加此类引用?我是这个环境中的新手:/
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    • 2015-06-07
    • 2014-08-30
    • 2012-05-19
    相关资源
    最近更新 更多