1
votes

I wanted to show the IIS configuration in a WPF-TreeView control. My OS is Windows 8.1 and i'm programming C# with VS2013. So i added a reference to the Microsoft.Web.Administration.dll and wrote the following code:

    using (ServerManager serverManager = new ServerManager())
    {
        foreach (var site in serverManager.Sites)
        {
            var siteNode = new TreeViewItem() { Header = string.Format("Site: {0}", site.Name) };
            _irv.trvIisInformation.Items.Add(siteNode);
            foreach (var application in site.Applications)
            {
                var appPoolNode = new TreeViewItem() { Header = string.Format("AppPool: {0}, Type: {1}", application.ApplicationPoolName, HoleApplikationstyp(serverManager, application)) };
                siteNode.Items.Add(appPoolNode);

                foreach (var virtDir in application.VirtualDirectories)
                {
                    appPoolNode.Items.Add(new TreeViewItem() { Header = string.Format("Dir: {0} [{1}]", virtDir.Path, virtDir.PhysicalPath) });
                }
            }
        }
    }

The ServerManager-object is created, but when i take a look into the object i see per example: ApplicationDefaults = "serverManager.ApplicationDefaults" has provoked an exception of type "System.Runtime.InteropServices.COMException".

And when the compiler want start the foreach-loop with the Sites of the ServerManager ...

System.Runtime.InteropServices.COMException wurde nicht behandelt. HResult=-2147221164 Message=Die COM-Klassenfactory für die Komponente mit CLSID {2B72133B-3F5B-4602-8952-803546CE3344} konnte aufgrund des folgenden Fehlers nicht abgerufen werden: 80040154 Klasse nicht registriert (Ausnahme von HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). Source=mscorlib ErrorCode=-2147221164 StackTrace: bei System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType) bei System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType) bei System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj) bei System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) bei System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) bei System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) bei System.Activator.CreateInstanceT bei Microsoft.Web.Administration.ConfigurationManager.CreateAdminManager[TClass,TInterface](WebConfigurationMap webConfigMap, Boolean isAdminConfig) bei Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap webConfigMap, String configPathToEdit, Boolean isAdminConfig) bei Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap configMap, String configPathToEdit, Boolean isAdminConfig) bei Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String rawConfigurationPath, String cacheKey, Boolean isAdminConfig) bei Microsoft.Web.Administration.ConfigurationManager.GetApplicationHostConfiguration() bei Microsoft.Web.Administration.ServerManager.GetApplicationHostConfiguration() bei Microsoft.Web.Administration.ServerManager.get_SitesSection() bei Microsoft.Web.Administration.ServerManager.get_Sites()

Does anybody know what to do?

Thanks in advance! Patrick

1

1 Answers

3
votes

Make sure IIS Management Scripts and Tools is installed on your machine (Under Add / Remove Programs -> Turn Windows Features on or off)