Ошибка недопустимого пространства имен в system.management - PullRequest
0 голосов
/ 18 июня 2020

У меня есть программа, которая будет запрашивать состояние ресурсов BizTalk, в частности, компонента ReceiveLocations. Когда я запускаю пример программы (полученной из C: \ Program Files (x86) \ Microsoft BizTalk Server 2013 R2 \ SDK \ Samples \ Admin \ WMI \ Enumerate Receive Locations ), я получаю сообщение об ошибке

Недопустимое пространство имен

В строке:

ManagementObjectCollection QueryCol = Searcher.Get();

Stack Trace

at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at Microsoft.Samples.BizTalk.WmiAdmin.EnumerateWMIClasses.Main(String[] args) in 
C:\Users\usename\Desktop\BIZTALK\CSharp\EnumRLs.cs:line 114

Это полная программа для запроса BizTalk services:

[STAThread]
    static void Main(string[] args)
    {
        // Display help information 
        if (args.Length > 0)
        {
                if (args[0] == "/?") 
                {
                    ....
                    ....
                }
        }

        try 
        {   
            //Create the WMI search object.
            ManagementObjectSearcher Searcher = new ManagementObjectSearcher();

            // create the scope node so we can set the WMI root node correctly.
            ManagementScope Scope = new ManagementScope("root\\"+server+"");
            Searcher.Scope = Scope;
        
            // Build a Query to enumerate the MSBTS_ReceiveLocation instances if an argument
            // is supplied use it to select only the matching RL.
            SelectQuery Query = new SelectQuery(); 
            if (args.Length == 0) 
                Query.QueryString="SELECT * FROM MSBTS_ReceiveLocation";
            else
                Query.QueryString="SELECT * FROM MSBTS_ReceiveLocation WHERE Name = '" + args[0] + "'";

            // Set the query for the searcher.
            Searcher.Query = Query;

            // Execute the query and determine if any results were obtained.
            ManagementObjectCollection QueryCol = Searcher.Get();

            // Use a bool to tell if we enter the for loop
            // below because Count property is not supported
            bool ReceiveLocationFound = false;

            // Enumerate all properties.
            foreach (ManagementBaseObject envVar in QueryCol)
            {
                // There is at least one Receive Location
                ReceiveLocationFound = true;

                Console.WriteLine("**************************************************");
                Console.WriteLine("Receive Location:  {0}", envVar["Name"]);
                Console.WriteLine("**************************************************");

                PropertyDataCollection envVarProperties = envVar.Properties;
                Console.WriteLine("Output in the form of: Property: {Value}");
            
                foreach (PropertyData envVarProperty in envVarProperties) 
                {                   
                    Console.WriteLine(envVarProperty.Name+ ":\t" + envVarProperty.Value);
                }
            }
                
            if (!ReceiveLocationFound) 
            {
                Console.WriteLine("No receive locations found matching the specified name.");
            } 
        }

        catch(Exception excep)
        {
            Console.WriteLine(excep.ToString());
        }
        
        Console.WriteLine("\r\n\r\nPress Enter to continue...");
        Console.Read();
        }

Я пробовал код в отдельном MVC приложении, где работают запросы WMI, но получаю ту же ошибку. Однако запросы WMI в приложении MVC предназначены для запроса статистики диска удаленного сервера, а не служб BizTalk Server. Я прошел через программу, и объект Query показывает следующее: https://drive.google.com/file/d/1natMNMkHP2KVUzt60sZSRjU3ecthSPox/view?usp=sharing

Что мне не хватает?

Есть что-нибудь конкретное c Мне нужно настроить запрос ресурсов BizTalk за пределами пространства имен System.Management, или это проблема самого образца кода?

...