Solved

console application cannt find ManagementObjectSearcher namespace

Posted on 2007-11-19
4
3,702 Views
Last Modified: 2013-12-17
Hi everyone im trying to write a console application to find the free space etc on a hard drive however it wont run but keeps telling me that the namespace cannt be found.  my code is below along with the error

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace serverInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("starting ok");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from win32_share");
            Console.WriteLine("object created ok");
        }
    }
}


Error      2      The type or namespace name 'ManagementObjectSearcher' could not be found (are you missing a using directive or an assembly reference?)      C:\Documents and Settings\AndrewSlaughter\Local Settings\Application Data\Temporary Projects\serverInfo\Program.cs      14      53      serverInfo
0
Comment
Question by:andrew67
  • 3
4 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 20312912
Not only do you need this line of code.

using System.Management;

But you need to add a Reference to the System.Management.dll library.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 50 total points
ID: 20312947
To add the library follow these steps.

Open the Solution Explorer window
Right click on the project name at the top of the tree view.
Click on Add Reference...
Select the .Net tab if it is not already selected.
Scroll down till you get to System.Management under Component Name and click on it to select it.
Click on the OK button.

It should work now.
0
 
LVL 3

Author Comment

by:andrew67
ID: 20312964
mega works a treat thanks
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 20312998
Not a problem, glad I was able to help. ;=)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now