Linux上的.Net Core Microsoft.Web.Administration ServerManager

时间:2018-12-06 13:44:22

标签: c# linux .net-core servermanager

.net核心版本:2.1.500

OS:Debian 9(4.9.0-8-amd64#1 SMP Debian 4.9.130-2(2018-10-27)x86_64 GNU / Linux )

我试图通过ServerManager从Linux操作系统停止/启动应用程序池,但是没有成功。 根据api目录,它应该可以正常工作: https://apisof.net/catalog/Microsoft.Web.Administration.ServerManager

在尝试到ApplicationPools时,ServerManager.OpenRemote()抛出NullReference异常:

// also trying ip adress
using (ServerManager manager = ServerManager.OpenRemote("someserver"))
{
    try
    {
        if (manager.ApplicationPools == null) /* <= Here is exception!!! */
        {
            Console.WriteLine("ApplicationPool is null!");
        }
        else
        {
            foreach (var item in manager.ApplicationPools)
            {
                Console.WriteLine("  " + item.Name);
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception: " + ex.Message);
        Console.WriteLine(" Trace=" + ex.StackTrace);
    }
}

结果:

  

异常:对象引用未设置为对象的实例。
  跟踪=   Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap   webConfigMap,字符串configPathToEdit,布尔值isAdminConfig,布尔值   isRedirectionConfig)       在Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap   configMap,字符串configPathToEdit,布尔值isAdminConfig,布尔值   isRedirectionConfig)       在Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String   rawConfigurationPath,字符串cacheKey,布尔值isAdminConfig,布尔值   isRedirectionConfig)       在Microsoft.Web.Administration.ServerManager.ApplicationPoolsSectionCreator()       在Microsoft.Web.Administration.Lazy.Initialize [T](T&目标,CreateInstanceDelegate 1 valueFactory) at Microsoft.Web.Administration.ServerManager.ApplicationPoolCollectionCreator() at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate 1 valueFactory)处       在some_file.cs:第123行的SomeMethod()中

当ServerManager通过带有字符串的ApplicationPools构造函数创建时,抛出System.PlatformNotSupportedException异常:

using (ServerManager manager = new ServerManager(@"\\someserver\IISSharedConfig\applicationHost.config"))
{
    try
    {
        if (manager.ApplicationPools == null) /* <= Here is exception!!! */
        {
            Console.WriteLine("ApplicationPool is null!");
        }
        else
        {
            foreach (var item in manager.ApplicationPools)
            {
                Console.WriteLine("  " + item.Name);
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception: " + ex.Message);
        Exception e = ex.InnerException;
        while (e != null)
        {
            Console.WriteLine("InnerException: " + e.Message);
            e = e.InnerException;
        }
        Console.WriteLine(" Trace=" + ex.StackTrace);
    }
}

结果:

  

Exception:调用的目标已引发异常。   InnerException:不支持COM Trace =在   System.RuntimeTypeHandle.CreateInstance(RuntimeType类型,布尔   publicOnly,布尔值wrapExceptions,布尔值和canBeCached,   RuntimeMethodHandleInternal&ctor)       在System.RuntimeType.CreateInstanceSlow处(布尔publicOnly,布尔wrapExceptions,布尔skipCheckThis,布尔fillCache)       在System.Activator.CreateInstanceT       在Microsoft.Web.Administration.ConfigurationManager.CreateAdminManager [TClass,TInterface](WebConfigurationMap   webConfigMap,布尔值isAdminConfig,布尔值isRedirectionConfig)       在Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap   webConfigMap,字符串configPathToEdit,布尔值isAdminConfig,布尔值   isRedirectionConfig)       在Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap   configMap,字符串configPathToEdit,布尔值isAdminConfig,布尔值   isRedirectionConfig)       在Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String   rawConfigurationPath,字符串cacheKey,布尔值isAdminConfig,布尔值   isRedirectionConfig)       在Microsoft.Web.Administration.ServerManager.ApplicationPoolsSectionCreator()       在Microsoft.Web.Administration.Lazy.Initialize [T](T&目标,CreateInstanceDelegate 1 valueFactory) at Microsoft.Web.Administration.ServerManager.ApplicationPoolCollectionCreator() at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate 1 valueFactory)处       在some_file.cs:第123行的SomeMethod()中

如何在Linux中使用ServerManager?

1 个答案:

答案 0 :(得分:0)

我相信 Linux 不支持您要执行的操作。请参阅您在问题中发布的link的底部:

  

平台

     

.NET Standard +平台扩展

据我所知,平台扩展是非跨平台的,因此不能在运行在 Linux 上的应用程序中使用。

您还可以在发布的第二个错误中看到提示:

  

不支持COM

Linux 上是正确的。

希望有帮助!