gpt4 book ai didi

c# - 来自 Linux 的 .Net Core Microsoft.Web.Administration ServerManager

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:15:03 24 4
gpt4 key购买 nike

.net核心版本:2.1.500

操作系统: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

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

据我所知,Platform Extensions 是不跨平台的附加项,因此不能用于在 Linux 上运行的应用程序。

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

COM is not supported

这在 Linux 上是正确的。

希望对您有所帮助!

关于c# - 来自 Linux 的 .Net Core Microsoft.Web.Administration ServerManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53652793/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com