[英]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
您使用了不正確的項目類型。 您需要使用.Net Framework,而不是.Net Core。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.