0

I created a new ASP.NET 5 projekt, started with the Rest example. I created a controller, worked pretty nice.

I want to run the server on my localhost. The assembly I want to use is "System.Diagnostics to get some information about my pc's hardware and display them on a website.

Everytime i wanna start the server to test it I get:

CS0246 C# The type or namespace name 'PerformanceCounterCategory' could not be found (are you missing a using directive or an assembly reference?)

What can I do in this case?

If i can deliver information that might be of use, tell me pls.

Here is the problematic class:

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# The type or namespace name 'PerformanceCounterCategory' could not be found (are you missing a using directive or an assembly reference?)

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"
  ]
}

Update: i created my own small dll that does nothing, if i try to use it, the same error appers, so it is happening with all references dlls, what am i doing wrong?

Update2: Hmm maybe this is the reason? http://imgur.com/v7DC6me

1

2 Answers 2

1

Did you misspell the name of the type or namespace? Without the correct name, the compiler cannot find the definition for the type or namespace. This often occurs because the casing used in the name of the type is not correct. For example, Dataset ds; generates CS0246 because the s in Dataset must be capitalized.

Look up more on the CS0246 at MSDN

1
  • I dont think so... heres my code, i edited the post. Is it possible that i cannot add such references in a asp.net api server? im a newbie in this environment : / Oct 17, 2015 at 21:40
0

You are using the incorrect project type. You need to use .Net Framework, instead of .Net Core.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.