4

Trying to get some WMI objects in a UWP application. Running VS2015 on .net 4.6.

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;
        }

    }


}

Errors

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

Any help would be appreciated.

Luke Griffith
  • 226
  • 4
  • 14
  • I've tested the same code in a C# Console Application and it appears to work fine - with no issues with references. I've added the System.Management reference to my Universal app... Could it be a problem with the new Universal App build? – Luke Griffith Oct 06 '15 at 17:02
  • 1
    You cannot use System.Management namespace in UWP app. Check available .net API for UWP here https://msdn.microsoft.com/en-us/library/windows/apps/mt185501.aspx – Alan Yao - MSFT Oct 10 '15 at 10:09
  • Have you fixed it? I'm facing the same issue – Bug Nov 21 '16 at 17:55

2 Answers2

1

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

Hopefully that helps someone out.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
AninOnin
  • 121
  • 4
0

This might work for you

foreach (ManagementObject mo in osDetailsCollection)
{
    foreach (PropertyData prop in mo.Properties)
    {
        if(prop.Name == "Caption")
        Details.OSName = prop.Value;
    }
}
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • Unfortunately not, its cut down on the number of errors I'm getting but still getting the same --- for each of the outer foreach and the .Get() method on osObjDetails. Thanks for looking :) – Luke Griffith Oct 06 '15 at 16:57