locked
new ManagementGroup RRS feed

  • General discussion

  • Hi All!
    I try to import management pack to SCOM via C# code
    Code:

                              String pack = "mynewpack.mp";

                         ManagementPack mp = new ManagementPack(pack);
                         ManagementGroup managementGroup = ManagementGroup.Connect("127.0.0.1");
                        managementGroup.ManagementPacks.ImportManagementPack(mp);


    it does not work.
    Ok. I try:


                   String pack = "mynewpack.mp";

                        ManagementPack mp = new ManagementPack(pack);

                   ManagementGroup managementGroup = new ManagementGroup("localhost");
                   managementGroup.ManagementPacks.ImportManagementPack(mp);

    it does not work.

    Ok. I try:

                        SecureString SecPassword = new SecureString();

                        string password = "pass";
                        for (int i = 0; i < password.Length; i++)
                        {
                            SecPassword.AppendChar(password[i]);
                        }

                        ManagementGroupConnectionSettings mgSettings = new ManagementGroupConnectionSettings("localhost");
                        mgSettings.Domain = "Domain";
                        mgSettings.UserName = "administrator";
                        mgSettings.Password = SecPassword;
                        ManagementGroup managementGroup = new ManagementGroup.Connect(mgSettings);

                        String pack = "mynewpack.mp";

                        ManagementPack mp = new ManagementPack(pack);
                        managementGroup.ManagementPacks.ImportManagementPack(mp);


    it does not work too.
    The program always falls on the line
    <code>ManagementGroup managementGroup = new ManagementGroup("localhost");
    </code>

    The error in all cases the same:
    <code>

    Class Initialization method Tests.ClassInitialize threw exception. Microsoft.EnterpriseManagement.Configuration.ExtensionException: Microsoft.EnterpriseManagement.Configuration.ExtensionException: Could not find property named Action on type System.Collections.Generic.ICollection`1[[Microsoft.EnterpriseManagement.Configuration.ManagementPackActionType, Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.</Message>
              <StackTrace>    at Microsoft.EnterpriseManagement.Configuration.ExtensionFactory.ProcessExtensionTypeMappings(ExtensionType extensionType, Type clrType, Dictionary`2 typeSpace)
       at Microsoft.EnterpriseManagement.Configuration.ExtensionFactory.ProcessExtensionTypeMappings(ExtensionType extensionType, Type clrType, Dictionary`2 typeSpace)
       at Microsoft.EnterpriseManagement.Configuration.ExtensionFactory.ComputeExtensionTypeSpace(ICollection`1 extensions)
       at Microsoft.EnterpriseManagement.Configuration.ExtensionRegistry.RefreshExtensionTypeSpace(Boolean forceRefresh)
       at Microsoft.EnterpriseManagement.Configuration.ExtensionRegistry.GetExtensions(Boolean forceRefresh)
       at Microsoft.EnterpriseManagement.Configuration.ExtensionRegistry.Initialize(IContainer container)
       at Microsoft.EnterpriseManagement.EnterpriseManagementGroupInternal.Initialize(SdkDataLayerProxyCore sdkDataLayerProxy, EnterpriseManagementConnectionSettings connectionSettings)
       at Microsoft.EnterpriseManagement.ManagementGroupInternal.Initialize(SdkDataLayerProxyCore sdkDataLayerProxy, EnterpriseManagementConnectionSettings connectionSettings)
       at Microsoft.EnterpriseManagement.EnterpriseManagementGroupInternal.Create[T](SdkDataLayerProxyCore sdkDataLayerProxy, EnterpriseManagementConnectionSettings connectionSettings)
       at Microsoft.EnterpriseManagement.Common.Internal.SdkDataLayerProxyCore.ConstructEnterpriseManagementGroupInternal[T,P](EnterpriseManagementConnectionSettings connectionSettings, ClientDataAccessCore clientCallback)
       at Microsoft.EnterpriseManagement.Common.Internal.SdkDataLayerProxyCore.RetrieveEnterpriseManagementGroupInternal[T,P](EnterpriseManagementConnectionSettings connectionSettings, ClientDataAccessCore callbackDispatcherService)
       at Microsoft.EnterpriseManagement.Common.Internal.SdkDataLayerProxyCore.Connect[T,P](EnterpriseManagementConnectionSettings connectionSettings, ClientDataAccessCore callbackDispatcherService)
       at Microsoft.EnterpriseManagement.ManagementGroup.InternalInitialize(EnterpriseManagementConnectionSettings connectionSettings, ManagementGroupInternal internals)
       at Microsoft.EnterpriseManagement.ManagementGroup..ctor(ManagementGroupConnectionSettings connectionSettings)
       at Microsoft.EnterpriseManagement.ManagementGroup.Connect(ManagementGroupConnectionSettings connectionSettings)
       at Tests.StaticHelpers.ImportManagementPacks(IEnumerable`1 packs)
       at Tests.ClassInitialize(TestContext context)

    </code>

    what am I doing wrong?


    Message from event viewer:
    A client has disconnected.  
    User name: Domain\Administrator 
    Session ID: uuid:qweqweqwe






    • Edited by compasses Thursday, July 28, 2016 3:51 PM
    • Changed type Elton_Ji Friday, August 5, 2016 6:42 AM
    Thursday, July 28, 2016 1:36 PM

All replies

  • Hi Sir,

    It seems that is beyond what we can support here .

    I'd suggest you to post it into developer's forum MSDN:

    https://social.msdn.microsoft.com/Forums/en-US/home

    Best Regards,

    Elton


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com .

    Saturday, July 30, 2016 8:48 AM
  • Hi

    can you post full code of references, have you add below references after SDK dll are added.

    using Microsoft.EnterpriseManagement;
    using Microsoft.EnterpriseManagement.Configuration;
    using Microsoft.EnterpriseManagement.Configuration.IO;

    refer below link for more information in connecting to MG.

    https://msdn.microsoft.com/en-us/library/hh329087.aspx

    Regards


    sridhar v

    Monday, August 1, 2016 5:45 AM
  • Full code:
    Main.cs:
        using System;
        using System.Collections.Concurrent;
        using System.Collections.Generic;
        using System.Diagnostics;
        static void Main(string[] args)
        {
              StaticHelpers.ImportMp();
        }


    StaticHelpers.cs:
        using Microsoft.EnterpriseManagement;
        using Microsoft.EnterpriseManagement.Administration;
        using Microsoft.EnterpriseManagement.Monitoring;
        using Microsoft.EnterpriseManagement.ConnectorFramework;
        using Microsoft.EnterpriseManagement.Common;
        using Microsoft.EnterpriseManagement.Packaging;
        using Microsoft.EnterpriseManagement.Configuration;
        using Microsoft.EnterpriseManagement.Configuration.IO;
        using Microsoft.EnterpriseManagement.Test.ScCommon;
        using Microsoft.EnterpriseManagement.Runtime;

        public class StaticHelpers
        {
              internal static void ImportMp() 
              {
                  String pack = "MyNewPack.mp";
                  ManagementGroup managementGroup = new ManagementGroup("localhost");
                  String currentDirecoty = AppDomain.CurrentDomain.BaseDirectory;
                  ManagementPack mp = new ManagementPack(Path.Combine(currentDirecoty, pack));
                  managementGroup.ManagementPacks.ImportManagementPack(mp);
             }
        }

    Tuesday, August 2, 2016 10:45 AM
  • Thank you. I will post this question into developer's forum MSDN
    Tuesday, August 2, 2016 10:46 AM