Background
Using Visual Studio to compile an application.
Ran into a little error.
Error Messages
Error Messages – Text
- 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
Troubleshooting
Code
Review Code
ManagementScope objManagementScope = null; ObjectQuery objObjectQuery = null; ManagementObjectSearcher objManagementObjectSearcher = null; ManagementObjectCollection objManagementObjectCollection = null;
Remediation
Outline
- Namespace
- The ManagementScope class belongs to the System.Management namespace
Link
- The ManagementScope class belongs to the System.Management namespace
- 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
- Within the Assemblies panel, add the following assemblies
- Access Menu
- Once the Project is saved
- The changes are effected in the .csproj file
Images
Image – Reference – Adding – Pre
Image – Reference – Adding – Post
Review
Review Files
.csproj
Images
Image – Pre
Image – Post
Explanation
The changes are:-
- System.Management is added