引用“组件"类型声称它在“系统"中定义 [英] Reference to type 'Component' claims it is defined in 'System'
本文介绍了引用“组件"类型声称它在“系统"中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图在UWP应用程序中获取一些WMI对象.在.net 4.6上运行VS2015.
Trying to get some WMI objects in a UWP application. Running VS2015 on .net 4.6.
ForEach和方法调用出现错误,指出对'组件'的引用类型是在'系统'中定义的",错误为CS7069.
I'm getting errors for the ForEach and method calls stating "Reference to type 'Component' claims it is defined in 'System'" with error CS7069.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management;
namespace SystemInfo
{
class wmiObject
{
static osDetails Program()
{
ManagementObjectCollection osDetailsCollection = getWMIObject("SELECT OSType, caption FROM Win32_OperatingSystem");
osDetails Details = new osDetails();
foreach (ManagementObject mo in osDetailsCollection)
{
Details.OSName = mo["Caption"].ToString();
}
osDetailsCollection = getWMIObject("SELECT Description, NumberOfLogicalProcessors, L3CacheSize from Win32_Processor");
foreach (ManagementObject mo in osDetailsCollection)
{
Details.NumberOfLogicalProcessors = mo["NumberOfLogicalProcessors"].ToString();
Details.L3CacheSize = mo["L3CacheSize"].ToString();
Details.Description = mo["Description"].ToString();
}
;
return Details;
}
static ManagementObjectCollection getWMIObject(string query)
{
ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(query);
ManagementObjectCollection osDetailsCollection = objOSDetails.Get();
return osDetailsCollection;
}
class osDetails
{
public string Description;
public string OSName;
public string NumberOfLogicalProcessors;
public string L3CacheSize;
}
}
}
错误
Severity Code Description Project File Line
Error CS7069 Reference to type 'Component' claims it is defined in 'System', but it could not be found SystemInfo C:\Users\Luke\Documents\GitHub\lgDns\lgDns\SystemInfo\SystemInfo\osDetails.cs 41
Error CS7069 Reference to type 'Component' claims it is defined in 'System', but it could not be found SystemInfo C:\Users\Luke\Documents\GitHub\lgDns\lgDns\SystemInfo\SystemInfo\osDetails.cs 18
Error CS7069 Reference to type 'Component' claims it is defined in 'System', but it could not be found SystemInfo C:\Users\Luke\Documents\GitHub\lgDns\lgDns\SystemInfo\SystemInfo\osDetails.cs 20
Error CS7069 Reference to type 'Component' claims it is defined in 'System', but it could not be found SystemInfo C:\Users\Luke\Documents\GitHub\lgDns\lgDns\SystemInfo\SystemInfo\osDetails.cs 26
Error CS7069 Reference to type 'Component' claims it is defined in 'System', but it could not be found SystemInfo C:\Users\Luke\Documents\GitHub\lgDns\lgDns\SystemInfo\SystemInfo\osDetails.cs 28
Error CS7069 Reference to type 'Component' claims it is defined in 'System', but it could not be found SystemInfo C:\Users\Luke\Documents\GitHub\lgDns\lgDns\SystemInfo\SystemInfo\osDetails.cs 29
Error CS7069 Reference to type 'Component' claims it is defined in 'System', but it could not be found SystemInfo C:\Users\Luke\Documents\GitHub\lgDns\lgDns\SystemInfo\SystemInfo\osDetails.cs 30
任何帮助将不胜感激.
推荐答案
我刚遇到此问题,发现的解决方案是将项目重新制作为C#WindowsFormsApp.它会自动添加参考:
I just encountered this problem, and the solution I found was to remake the project as a C# WindowsFormsApp. It automatically added the references:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Microsoft.CSharp.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Core.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Data.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Data.DataSetExtensions.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Deployment.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Drawing.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Net.Http.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Windows.Forms.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Xml.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Xml.Linq.dll
希望能帮助到某人.
这篇关于引用“组件"类型声称它在“系统"中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文