Share via

ManagementObjectCollection Error

OSVBNET 1,401 Reputation points
2022-06-09T23:33:54.727+00:00

Hello experts,
Any idea how to eliminate this error:

Dim m_drive As String = Path.GetPathRoot(Environment.SystemDirectory)
m_drive = m_drive.Substring(0, m_drive.Length - 1)
Dim m_searcher As New ManagementObjectSearcher("root\Microsoft\Windows\Storage", "SELECT * FROM MSFT_PhysicalDisk WHERE DeviceId = " + GetPhysicalDriveId(m_drive, True))
Dim m_query As ManagementObject = TryCast(m_searcher.Get(0), ManagementObject)

Error: Class 'System.Management.ManagementObjectCollection' cannot be indexed because it has no default property.

No idea why adding System.Linq will eliminate it, but anyway not to import System.Linq and get rid of this error?
Thanksss :)

Developer technologies | VB

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.