Visual Studio – Compilation – Error – “The type or namespace name ‘ManagementScope’ could not be found (are you missing a using directive or an assembly reference?)”

Background

Using Visual Studio to compile an application.

Ran into a little error.

Error Messages

Error Messages – Text

  1. Error CS0246
    • The type or namespace name ‘ManagementScope’ could not be found (are you missing a using directive or an assembly reference?)
    • The type or namespace name ‘ObjectQuery’ could not be found (are you missing a using directive or an assembly reference?)
    • The type or namespace name ‘ManagementObjectSearcher’ could not be found (are you missing a using directive or an assembly reference?)
    • The type or namespace name ‘ManagementObjectCollection’ could not be found (are you missing a using directive or an assembly reference?)

Error Messages – Image

error.CS0246.01.20200723.0856PM

Troubleshooting

Code

Review Code


ManagementScope             objManagementScope = null;
ObjectQuery                 objObjectQuery = null;
ManagementObjectSearcher    objManagementObjectSearcher = null;
ManagementObjectCollection  objManagementObjectCollection = null;

Remediation

Outline

  1. Namespace
    • The ManagementScope class belongs to the System.Management namespace
      Link
  2. Add Reference to System.Management namespace to the project
    • Access Menu
      • Menu Item – Project / Add Reference
      • Access the Assemblies panel
        • Within the Assemblies panel, add the following assemblies
          • System.Management
  3. Once the Project is saved
    • The changes are effected in the .csproj file

Images

Image – Reference – Adding – Pre

addReferences.System.Management.01.20200723.0908PM.PNG

Image – Reference – Adding – Post

addReferences.System.Management.02.20200723.0909PM

Review

Review Files

.csproj

Images

Image – Pre

csproj_01.PNG

Image – Post

csproj_02

Explanation

The changes are:-

  1. System.Management is added

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s