.Net Core Microsoft.Web.Administration ServerManager 来自 Linux
.Net Core Microsoft.Web.Administration ServerManager from Linux
.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 stop/start 来自 Linux OS 的应用程序池,但没有成功。
根据 api 目录,它应该可以工作:
https://apisof.net/catalog/Microsoft.Web.Administration.ServerManager
ServerManager.OpenRemote() 尝试 ApplicationPools 时抛出 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);
}
}
结果:
Exception: Object reference not set to an instance of an object.
Trace= at
Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap
webConfigMap, String configPathToEdit, Boolean isAdminConfig, Boolean
isRedirectionConfig)
at Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap
configMap, String configPathToEdit, Boolean isAdminConfig, Boolean
isRedirectionConfig)
at Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String
rawConfigurationPath, String cacheKey, Boolean isAdminConfig, Boolean
isRedirectionConfig)
at Microsoft.Web.Administration.ServerManager.ApplicationPoolsSectionCreator()
at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate1 valueFactory)
at Microsoft.Web.Administration.ServerManager.ApplicationPoolCollectionCreator()
at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate
1 valueFactory)
at SomeMethod() in some_file.cs:line 123
当 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: Exception has been thrown by the target of an invocation.
InnerException: COM is not supported Trace= at
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean
publicOnly, Boolean wrapExceptions, Boolean& canBeCached,
RuntimeMethodHandleInternal& ctor)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstanceT
at Microsoft.Web.Administration.ConfigurationManager.CreateAdminManager[TClass,TInterface](WebConfigurationMap
webConfigMap, Boolean isAdminConfig, Boolean isRedirectionConfig)
at Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap
webConfigMap, String configPathToEdit, Boolean isAdminConfig, Boolean
isRedirectionConfig)
at Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap
configMap, String configPathToEdit, Boolean isAdminConfig, Boolean
isRedirectionConfig)
at Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String
rawConfigurationPath, String cacheKey, Boolean isAdminConfig, Boolean
isRedirectionConfig)
at Microsoft.Web.Administration.ServerManager.ApplicationPoolsSectionCreator()
at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate1 valueFactory)
at Microsoft.Web.Administration.ServerManager.ApplicationPoolCollectionCreator()
at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate
1 valueFactory)
at SomeMethod() in some_file.cs:line 123
如何在Linux中使用ServerManager?
我相信 Linux 不支持您尝试执行的操作。请参阅您在问题中发布的 link 底部:
Platform
.NET Standard + Platform Extensions
据我所知,平台扩展 是非跨平台的附加功能,因此不能在 上的应用程序 运行 中使用Linux.
您还可以在发布的第二个错误中看到提示:
COM is not supported
在 Linux 上是正确的。
希望对您有所帮助!
.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 stop/start 来自 Linux OS 的应用程序池,但没有成功。 根据 api 目录,它应该可以工作: https://apisof.net/catalog/Microsoft.Web.Administration.ServerManager
ServerManager.OpenRemote() 尝试 ApplicationPools 时抛出 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);
}
}
结果:
Exception: Object reference not set to an instance of an object.
Trace= at Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap webConfigMap, String configPathToEdit, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap configMap, String configPathToEdit, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String rawConfigurationPath, String cacheKey, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ServerManager.ApplicationPoolsSectionCreator() at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate1 valueFactory) at Microsoft.Web.Administration.ServerManager.ApplicationPoolCollectionCreator() at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate
1 valueFactory) at SomeMethod() in some_file.cs:line 123
当 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: Exception has been thrown by the target of an invocation. InnerException: COM is not supported Trace= at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean skipCheckThis, Boolean fillCache) at System.Activator.CreateInstanceT at Microsoft.Web.Administration.ConfigurationManager.CreateAdminManager[TClass,TInterface](WebConfigurationMap webConfigMap, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ConfigurationManager.CreateWritableAdminManager(WebConfigurationMap webConfigMap, String configPathToEdit, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ConfigurationManager.CreateConfiguration(WebConfigurationMap configMap, String configPathToEdit, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ConfigurationManager.GetConfiguration(String rawConfigurationPath, String cacheKey, Boolean isAdminConfig, Boolean isRedirectionConfig) at Microsoft.Web.Administration.ServerManager.ApplicationPoolsSectionCreator() at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate
1 valueFactory) at Microsoft.Web.Administration.ServerManager.ApplicationPoolCollectionCreator() at Microsoft.Web.Administration.Lazy.Initialize[T](T& target, CreateInstanceDelegate
1 valueFactory) at SomeMethod() in some_file.cs:line 123
如何在Linux中使用ServerManager?
我相信 Linux 不支持您尝试执行的操作。请参阅您在问题中发布的 link 底部:
Platform
.NET Standard + Platform Extensions
据我所知,平台扩展 是非跨平台的附加功能,因此不能在 上的应用程序 运行 中使用Linux.
您还可以在发布的第二个错误中看到提示:
COM is not supported
在 Linux 上是正确的。
希望对您有所帮助!